- Home /
Accessing BuildSettings from BuildSettings.asset
I'm using a C# script to call BuildPipeline to make standalone and web player versions of our simulation. I couldn't find a way to access the list of scenes to build under the Build Settings UI. Now I see in Library there's a file called BuildSettings.asset. Can I use the AssetBundle API to load this and read the build settings automatically from my project so as not to hardcode the list of scenes into my project file? If not, where can I access the list of scenes that are displayed in the Build Settings UI?
Answer by pahe · Mar 21, 2011 at 02:11 PM
Maybe what you are seeking is the editorbuildsettings.scenes ? I don't know if you can add new scenes to it, but It provides the information you want to have (path to the scene and if it is enabled in your building scene settings).
hope that was helpful.
regards
Edit: tried myself to add new scenes to the scenes and it works. So if you have all your gamescenes in one directory you can read all filenames from this directory and add them to the editorbuildsettings.scenes automatically.
Answer by Neodrop · Jan 25, 2012 at 03:05 PM
private static string[] FillLevels()
{
return (from scene in EditorBuildSettings.scenes where scene.enabled select scene.path).ToArray();
}
Answer by AntonStruyk · Oct 14, 2011 at 02:58 PM
You can do something like the following in order to modify the set of scenes in the 'Build Settings' menu via an editor script:
var original = EditorBuildSettings.scenes;
var newSettings = new EditorBuildSettingsScene[original.Length + 1];
System.Array.Copy(original, newSettings, original.Length);
var sceneToAdd = new EditorBuildSettingsScene("Assets/Path/To/Scene/sceneName.unity", false);
newSettings[newSettings.Length - 1] = sceneToAdd;
EditorBuildSettings.scenes = newSettings;
That will add a new scene to the list of scenes. You can remove scenes or modify the 'enabled' property by accessing the same EditorBuildSettings.scenes array.
Answer by jonas-echterhoff · Jan 23, 2010 at 02:54 PM
While you cannot change the selected scenes displayed in the build settings window from a script, you can make custom builds using BuildPipeline.BuildPlayer, which lets you pass the scenes to build as a parameter.
Right but I don't want to have to specify the names of the scenes, I want to access the list of scenes to compile from wherever they are stored when they are set by the user in Unity. Then if the user were to edit the list of scenes in the Build Settings UI, my continuous integration script would automatically include the new scene. As it is now, the scene list is hardcoded in the build script and so has to be updated if the build settings are changed.
I don't think it is possible to get this information from a script. $$anonymous$$y advise is to implement a custom build solution using BuildPipeline.BuildPlayer, and implement your own scene list management.
Answer by Russ Gresh · Jul 30, 2010 at 06:11 PM
a hacky way I found to do it is just read the EditorBuildSettings.asset file in as a string and scan for ".unity". The scene paths are stored in there, but so is the build name so make sure the ".unity" isn't followed by "3d"
Yeah, if doing this from a command line script in OS X or similar OS you can use 'strings -a BuildSettings.asset | grep unity' and you'll see the list there. Its an ok answer but as you said, its a hack.
Hi, I tried doing this from inside Unity using a streamreader and the www class. Both methods fail and return an empty file. Any ideas?
Note: When i open the file in notepad the file has text in it (and symbols etc) but when i open it inside monodevelop it appears empty.
editorbuildsettings.scenes is useless for what i want to do because it only works inside an editor script >.<. $$anonymous$$assive fail unity3d.