Is it possible inside Unity (5.6.7f1) to add a specific scene from a path to the build settings (slot 0) in c#?
Bonus, I’m also trying to work out how to check if the scene is already in that position in the build settings, but I haven’t been able to find anything online about assigning a specific scene to a specific slot in there and thought I’d ask you guys to see if anyone knows how to do any of this.
BuildPlayerOptions options = new BuildPlayerOptions();
options.scenes = new string[]
{
"Assets/Scenes/Default.unity",
"Assets/Scenes/Another.unity"
};
BuildPipeline.BuildPlayer(options);
Sorry, specifically want to add it to the top of the list regardless of what is already in there.
Is it possible to grab the existing options and add to the top?
That way I could check if it is already in there.
So you’ll need to get the current build options for .scenes - a quick search came up with this:
https://answers.unity.com/questions/1642506/getting-the-current-buildoptions.html
As I can’t seem to use “BuildPlayerWindow” at all due to protection level, I decided to just have a manual button that overrides the existing stuff in the editor, but it isn’t working.
This is in the editor window.
if(GUILayout.Button("Add '_preload' to Build Settings"))
{
ResetBuildSettings();
}
And this is its call, but for some reason it doesn’t appear ot do anything or even trigger any errors.
void ResetBuildSettings()
{
BuildPlayerOptions bpo = new BuildPlayerOptions();
bpo.scenes = new string[]
{
"Assets/ArcaneEngine/Scenes/_preload.unity"
};
BuildPipeline.BuildPlayer(bpo);
}
Try:
BuildPlayerOptions options = new BuildPlayerOptions();
options.scenes = new string[]
{
"Assets/ArcaneEngine/Scenes/_preload.unity"
}
options.locationPathName = path + "\\name.exe"; // Windows
// options.locationPathName = path + "\\name.apk"; // Android
// options.locationPathName = path + "\\name.x86_64"; // Linux
// options.locationPathName = path; // WebGL
options.target = EditorUserBuildSettings.activeBuildTarget;
BuildPipeline.BuildPlayer(options);