6
\$\begingroup\$

This is somewhat of an extension to this question.

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 and 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 the Unity Editor. Is that possible?

I used Unity to create a framework, and now the client wants to use this framework to generate more games without using the Unity Editor, only through XML files.

I know that one can read XML files with Unity, but how can one create a scene, fill it with GameObjects, and load prefabs all using a standalone build, not the editor? Is there any other way to do what I've described?

\$\endgroup\$
  • 1
    \$\begingroup\$ I don't believe you can build scenes without the editor( either in a game build or asset bundle build ), but why not just build a single scene and manage what a scene is yourself? If you're not using the editor, what do you gain by using Unity's scenes? \$\endgroup\$ – Ben Jun 17 '15 at 9:37
  • 1
    \$\begingroup\$ You are doing it wrong. This is adding a ton of complexity, for seemingly no reason. That being said, you could generate your scenes via XML files, just as long as you have all your prefabs already created. \$\endgroup\$ – jgallant Jun 17 '15 at 11:17
  • \$\begingroup\$ @Jon I guess you're right. I'll create a simple scene with my prefabs, and then just parse the XML file to create the gameobjects and other links. \$\endgroup\$ – DBoxer Jun 18 '15 at 1:56
  • \$\begingroup\$ It sounds like your client may be treading close to legal concerns. I'd be careful you don't violate any of the EULA with Unity. Some of what it sounds like may fall within the realm of repackaging and redistributing their engine, as it pretty much sounds like they want you to re-skin Unity so they don't have to pay a licensing fee for their particular application. C.Y.A. man \$\endgroup\$ – Stephan Jun 25 '15 at 18:19
  • \$\begingroup\$ What you're trying to do is creating an exe that emulates/simulates Unity Editor. Bad idea. Probably not possible to create scenes like that. \$\endgroup\$ – lvictorino May 21 '16 at 9:24
4
\$\begingroup\$

You can do something like this. It looks monumentally stupid (Unity has an awesome editor, why not use it?), but just in case you do have a good reason:

  1. You can't create scenes programmatically, but you can have an empty scene and add whatever you need programmatically.
  2. Using prefabs is probably not the best idea: prefabs are usually loaded only when referenced in the scene. You can build a big list of all required prefabs in your game, and reference it, but then they all will be in memory - even the ones you don't need.
  3. Better use Asset Bundles - pack all your assets into bundles. Your bundle-building script can also save whatever metadata you need - so you'd have a list of all bundles, with IDs or names or whatever. Then when creating a scene from XML, you can load required bundles and instantiate the objects. Note that you'd probably have to "patch" the references by hand - e.g. if a model bundle needs a texture from another bundle, Unity may not find the texture automatically.
  4. The Asset Bundles would still have to be built using Unity Editor. If what you want is loading raw assets (e.g. .fbx or .png files) you'd have to write your own parser to load them, or look at Asset Store - there are loaders for some more popular formats there. However, at this point, you should actually stop using Unity as it's causing more trouble than it's saving.
\$\endgroup\$
3
\$\begingroup\$

Unity 2017.3 supports the concept of creating scenes directly at either runtime or edittime.

see SceneManager.CreateScene()

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.CreateScene.html

Create an empty new Scene at runtime with the given name.

The new Scene will be opened additively into the hierarchy alongside any existing Scenes that are currently open. The path of the new Scene will be empty. This function is for creating Scenes at runtime. To create a Scene at edit-time (for example, when making an editor script or tool which needs to create Scenes), use EditorSceneManager.NewScene.

You could also use something like this scriptable objects and json example to create both built in and user generated levels:

https://youtu.be/VBA1QCoEAX4?t=1261

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.