Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
3
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 this field with the currently selected items in the BuildSettings window.

Previousely EditorUserBuildSettings.architectureFlags was used for this, however this 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 something like this:

 BuildPlayerOptions buildOptions = GetCurrentBuildOptions();

But no such thing seems to exist as far as I can see by reading the documentation.

Thanks in advance!

Comment
Add comment
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
7
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 something like this:

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

If you don't want to be prompted for an output folder, things get a little trickier. In this 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
Add comment · Show 4 · 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.DefaultBuild$$anonymous$$ethods) this worked for me in 2019.3.0f6

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

@$$anonymous$$inchuilla's addition is still working as of 2019.4.4f1.

It kills me that turning off Development Build doesn't turn off the #DEVELOP$$anonymous$$ENT_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);



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.

Follow this Question

Answers Answers and Comments

121 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

Related Questions

Set dynamicBatching player setting via editor script? 0 Answers

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

What is the difference between BuildTarget and BuildTargetGroup 0 Answers

Share same assets with multiple standalone builds 0 Answers

Platform switch to trigger a function 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