- Home /
Can scenes be converted into objects?
Is there a process or function that can convert a scene into a compound object? I am building a randomly generated maze and have several different parts of the maze saved in multiple scenes. Is there a way to take a scene an make into a empty object with all other objects in the scene parented to it? this would be a really useful feature, especially in random generation. thanks!
Could you convert your maze sections from different scenes into prefabs. Then assemble these on the fly in a single scene ins$$anonymous$$d?
Answer by Jeff-Kesselman · Nov 11, 2014 at 07:37 PM
yes and no.
No you cannot "convert a scene into an object". A scene has much more information then an object.
However what you CAN do is make a prefab of the part of the scene Hierarchy you wish to transfer, and then export a package with that prefab in it.
You can also programmatically load a scene into another one, however thats fraught with peril and probably not what you really want.
Edit: it occurs to me, though you didn't say this, that you may mean you want to do this at runtime of the game.
The only way to do that is to make prefabs and export them as bundles. Bundles are a pro feature.
Could he not make it a prefab in one of his scenes and then just add at runtime in another scene. All his maze parts are, from the sound of it, already in the same project.
Just want to add that AssetBundles aren't required for having parts of the scene stored in prefabs. AssetBundles are just a way to load assets at runtime which aren't part of the project when the project got build. Also exporting as package is only needed when you want to transfer those assets into a different project,
using LoadLevelAdditiveAsync (pro only):
http://docs.unity3d.com/ScriptReference/Application.LoadLevelAdditiveAsync.html
it is possible to do what you are asking. In your individual scenes parent all your objects to a gameobject with a meaningful name.
There is no way to get that object after the async load is complete unless you use GameObject.Find();
http://docs.unity3d.com/ScriptReference/GameObject.Find.html
The good thing about loading additive async is that it will bring the assets into your scene on a separate thread. I have tried this with a number of tiles loaded during runtime and it worked alright. The best solution I found (and the least framerate intrusive) is to just run the random generation at the very start of your game. Since you are bound to have a load time, load all the prefabs into the scene at that point and just turn them off/on based on player position
Right, bundles are oly if you want to load new assets at run time. Thought I made that clear shrug
@b1gry4n: There's also LoadLevelAdditive which doesn't require Unity pro. The "async" versions (which are pro only) are just non blocking calls as they load the scene in the background. For small scenes you might not even notice the small hiccup when using the non-async version. However you're right about accessing the objects contained in the scene.
Your answer
Follow this Question
Related Questions
Static variable problem when using same script on multiple objects! 1 Answer
Best pipeline to import multiple weapons into Unity for characters? 2 Answers
Putting Together Multiple Rigged Models 1 Answer
How can i set multiple Texture or Sprite with script? 1 Answer
How to stop a random string generator from repeating a string consecutively? 1 Answer