x


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?

more ▼

asked Jan 22 '10 at 04:46 PM

Ben 2 gravatar image

Ben 2
473 20 24 41

(comments are locked)
10|3000 characters needed characters left

6 answers: sort voted first

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.

more ▼

answered Mar 21 '11 at 02:11 PM

pahe gravatar image

pahe
124 3 4 13

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 14 '11 at 02:58 PM

AntonStruyk gravatar image

AntonStruyk
76 9 11 14

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jan 23 '10 at 02:54 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

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.

Jan 24 '10 at 04:49 AM Ben 2

I don't think it is possible to get this information from a script. My advise is to implement a custom build solution using BuildPipeline.BuildPlayer, and implement your own scene list management.

Jan 24 '10 at 02:19 PM jonas echterhoff ♦♦
(comments are locked)
10|3000 characters needed characters left
private static string[] FillLevels()
{
    return (from scene in EditorBuildSettings.scenes where scene.enabled select scene.path).ToArray();
}
more ▼

answered Jan 25 '12 at 03:05 PM

Neodrop gravatar image

Neodrop
46

(comments are locked)
10|3000 characters needed characters left

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"

more ▼

answered Jul 30 '10 at 06:11 PM

Russ Gresh gravatar image

Russ Gresh
12 1

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.

Aug 02 '10 at 05:56 PM Ben 2

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 >.<. Massive fail unity3d.

May 26 '11 at 09:46 AM Gungnir
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x663
x419
x383
x63

asked: Jan 22 '10 at 04:46 PM

Seen: 5754 times

Last Updated: Jan 25 '12 at 03:05 PM