- Home /
Creating Scenes Programmatically From A Deployed Build in Unity
This is somewhat of an extension to this question: http://answers.unity3d.com/questions/513801/programatically-creating-entire-unity-games.html
I have a client who would like to create an entire game only using XML files. This is how the process should go like:
Build & Run a "GameCreator" project. Read an XML file that has the attributes of all the scenes. Create new scenes, fill it with new GameObjects, and load some prefabs. Deploy this new project as a standalone build. All of the above should NOT use Unity Editor. Is that possible ??
What happened is that I used Unity to create a "Framework", and the client wants to use this framework to generate more games without using Unity Editor, only through XML files.
I know that one can read XML files with Unity, but how to create a scene, fill it with GameObjects, load prefabs all using a standalone build, not the editor ?? Is there any other way to do what I've described ??
Thanks.
To go from a scene file to a runtime scene, you kinda need the editor, as that bakes together all the parts of your project to playable things.
A scene in Unity contains a bunch of plain objects, and a bunch of prefabs. In addition, it contains a bunch of links to assets in your Assets folder.
When the levels are built (or you press play in the editor), all of that stuff is baked together to create an actual level. That process happens under the hood - you can hook into it, and I believe you can run it from the command line, but you need the editor for it to happen.
So making new, standalone builds won't work. What you can do is to make a program that parses the xml files to create levels (and level selection menus) by adding things to an empty scene with some hook scripts. Creating a new "game" would then mean bundling your prebuilt Unity executable together with those xml files.
You can probably write a program that turns that bundle into a standalone .exe, which will give the impression of doing exactly what you're asking for.
Or you could buy source access from Unity to be able to extract the building-part of the editor, but source access costs so much that it's not even listed.
@baste, thanks for the speedy reply. I guess Unity was made to be used as "Unity". I'll try my luck by creating a simple scene, parsing the X$$anonymous$$L file, and creating the game objects there.
Answer by Peter Suwara · Aug 04, 2015 at 05:56 AM
Try using the following during a Build Script call from the command line :
EditorApplication.NewScene
... Do your thing with assets/prefabs.
EditorApplication.SaveScene
That actually could work, but the problem is that I can't use anything related to Unity tools, even the command line.
I ended up creating a "base" game that loads up an X$$anonymous$$L file and generates the content accordingly. Thanks for the answer though.
That would definitely work. Essentially what you have done is built a tool created by unity, to create data that can then be parsed by another executable built with unity, which does the parsing and creation of objects in realtime. :)
Nice one !
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Programatically creating entire Unity games 2 Answers
Distribute terrain in zones 3 Answers