I need to keep a gameobject (“ConstructionManager”) intact when creating new scenes in the editor. Is there some way to make something work like DontDestroyOnLoad(target) in the editor?
There’s a lot of data in my ContructionManager-gameobject that I use to build my levels and right now I need to manually set all these when creating a new scene which is a bit of a hassle.
You can have your manager as a prefab. Then all you need to do is add that prefab to all scenes and you’re set. Any change you make to the actual prefab-asset (in the project hierarchy) will be reflected in all the instances of that prefab (in the scene hierarchy).
Note that if you change the values in any instance of a prefab, those changes will be for that scene only. The per-scene changes will override any values from the prefab-asset, but you will notice if this happens from the bold-faced variable in the inspector.
Alternatively, if you don’t need the Unity callbacks (Update, Awake etc.) you could possibly pull this off with a ScriptableObject, as frarees suggests.
Hm, “Save Scene As” > new scene name? Then delete the objects that you don’t want anymore?
Yeah that of course works when creating the scene but when working in that level I might be adding new stuff to ConstructionManager that will then need to be persistent in other levels... It will work for now though!
Do you have to keep it the object in the scene for things to work? Have you tried ScriptableObjects? This way your data gets serialized properly and does not depend on your actual scene.
Hmm I'll need to look into this I guess. So if I have a list of prefab references I could put that list in a class deriving from scriptable object? How then will I refer to it in code? If you could elaborate a little then this is probably what I have been looking for...
If you want to refer GameObject references, you could do something like: public class MyConstructionData : ScriptableObject { public GameObject[] prefabs; } ScriptableObjects hold serialized data. They are assets, e.g. materials and terrain. Here's an example of how to create them http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset The interesting part goes into editor scripting i.e. how do you create an inspector/editor window to manage the scriptable object. That depends on what you actually want. Take a look at unity docs about editor scripting.
Prefab Maybe?
– Seth-McCumber