• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by RobAEG · Jun 21, 2019 at 09:35 AM · editor-scriptingbuild settingsbuildpipelinebuildsautomated

Getting the current BuildOptions

I'm trying to autmate the build process and I have the following problem:

When calling BuildPipeline.BuildPlayer it expects a BuildPlayerOptions object with a BuildOptions field. I would like to fill t$$anonymous$$s field with the currently selected items in the BuildSettings window.

Previousely EditorUserBuildSettings.arc$$anonymous$$tectureFlags was used for t$$anonymous$$s, however t$$anonymous$$s is now no longer part of Unity.

The BuildSettings window settings also don't seem to be saved in the EditorBuildSettings.asset file in the ProjectSettings window, so parsing the YAML file is also out of the question.

Essentially I would like to do somet$$anonymous$$ng like t$$anonymous$$s:

 BuildPlayerOptions buildOptions = GetCurrentBuildOptions();

But no such t$$anonymous$$ng seems to exist as far as I can see by reading the documentation.

Thanks in advance!

Comment
nratcliff
tezza2k1
will_unity731
unity_E9FfAw7RsMp7yg

People who like this

4 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by nratcliff · Jun 25, 2019 at 12:55 PM

BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions() (source) might be what you're looking for. It calls the internal function GetBuildPlayerOptionsInternal() and will always open a window prompting for a output directory. GetBuildPlayerOptions() takes a "default" instance of BuildPlayerOptions as a parameter, but you can pass a new instance if you don't have any specific options you'd like to provide as default.

If you don't mind being prompted for a build folder, your GetCurrentBuildOptions() method could look somet$$anonymous$$ng like t$$anonymous$$s:

 static BuildPlayerOptions GetCurrentBuildOptions(
     BuildPlayerOptions defaultOptions = new BuildPlayerOptions()) 
 {
     return BuildPlayerWindow.DefaultBuildMethods.GetBuldPlayerOptions(defaultOptions);
 }

If you don't want to be prompted for an output folder, t$$anonymous$$ngs get a little trickier. In t$$anonymous$$s case, I'd use reflection:

 static BuildPlayerOptions GetBuildPlayerOptions(
     bool askForLocation = false,
     BuildPlayerOptions defaultOptions = new BuildPlayerOptions())
 {
     // Get static internal "GetBuildPlayerOptionsInternal" method
     MethodInfo method = typeof(BuildPlayerWindow).GetMethod(
         "GetBuildPlayerOptionsInternal",
         BindingFlags.NonPublic | BindingFlags.Static);
 
     // invoke internal method
     return (BuildPlayerOptions)method.Invoke(
         null, 
         new object[] { askForLocation, defaultOptions});
 }

As always with reflection, be aware that the internal method signature is subject to change, and may cause your build scripts to break in future editor versions.

Comment
RobAEG
Minchuilla
tezza2k1
PavelKlym
Vanilla-Plus
manutoo
Zarkend
unity_E9FfAw7RsMp7yg

People who like this

8 Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobAEG · Jun 26, 2019 at 03:26 PM 0
Share

Hey @nratcliff thanks for taking the time to answer. Reflection seems to be the (only?) way to get these settings. Since I don't have the luxury to ask for a directory due to the editor being run in headless mode

The function throws an exception for me due to EditorUserBuildSettings.GetBuildLocation(buildTarget);not returning a valid path. So it seems I have to implement the GetDefaultBuildPlayerOptions function myself based on the documentation on github. Which is unfortunate.

I'll mark your answer as accepted for now, since there are no other/better answers at this time.

avatar image Minchuilla · Feb 11, 2020 at 04:59 PM 2
Share

After changing the typeof(BuildPlayerWindow) to typeof(BuildPlayerWindow.DefaultBuildMethods) this worked for me in 2019.3.0f6

avatar image Vanilla-Plus · Oct 10, 2020 at 05:35 AM 0
Share

@Minchuilla's addition is still working as of 2019.4.4f1.

It kills me that turning off Development Build doesn't turn off the #DEVELOPMENT_BUILD define. What a weird thing not to do..? I'm trying to have a dynamic build path for Addressable content bundles and this has been one of the hardest parts!

avatar image gregtom7 · Mar 29, 2021 at 04:27 PM 0
Share

In 2019.2.6 in the line:

 MethodInfo method = typeof(BuildPlayerWindow).GetMethod(
          "GetBuildPlayerOptionsInternal",
          BindingFlags.NonPublic | BindingFlags.Static);

instead of that line you need to insert:

 MethodInfo method = typeof(BuildPlayerWindow.DefaultBuildMethods).GetMethod(
          "GetBuildPlayerOptionsInternal",
          BindingFlags.NonPublic | BindingFlags.Static);



avatar image virtualjay · Nov 16, 2022 at 06:51 PM 0
Share

Unfortunately, this stopped working for me when we went to Unity 2021.3. It now always prompts for the location, whereas it did not before. I am using gregtom7's version of the code.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is the difference between BuildTarget and BuildTargetGroup 0 Answers

Set dynamicBatching player setting via editor script? 0 Answers

Is there a some sort of OnBuild() event for the editor? 1 Answer

Share same assets with multiple standalone builds 0 Answers

Add/Remove scene to build settings from editor script and run levels in editor 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges