- Home /
Unity 4.6 Copying Complex GameObjects Between Scenes Resets Fields In the Editor
If I try to copy game objects that have a lot of working parts (specifically canvases) between scenes, the fields get cleared and it's way too much work to re-enter them manually. Can anyone explain an elegant way to do this?
Answer by Baintastic · Jan 13, 2015 at 09:22 PM
Okay, I found a workaround for this. It's a little ugly, but it works like a charm.
Add the code below to a new Javascript file in your project.
Create a new scene.
In the project panel, select the scene that has the gameobject(s) you want to copy.
File > Load Scene [Additive] <-- NEW FEATURE WOW! This will copy the whole existing scene into your new scene.
Remove all gameobjects that you just imported except for the one(s) you want to copy.
Save the scene.
Open the scene you want to copy the gameobjects into.
In the project panel, select the scene you created.
File > Load Scene [Additive] again and GREAT SUCCESS!
#if UNITY_EDITOR
@MenuItem("File/Load Scene [Additive]")
static function Apply () { var strScenePath : String = AssetDatabase.GetAssetPath(Selection.activeObject); if (strScenePath == null) { EditorUtility.DisplayDialog("Select Scene", "You Must Select a Scene first!", "Ok"); return; } Debug.Log("Opening " + strScenePath + " additively"); EditorApplication.OpenSceneAdditive(strScenePath); return; } #endif
source: http://forum.unity3d.com/threads/scene-copy-game-objects-from-one-scene-to-another.19803/
Since Unity5, copying Canvas GameObjects (the reason for this post) has improved significantly, so this method isn't all that useful to me anymore.
Hey Baintastic. Cheers for taking the time to share what you found. I'm running into similar territory. The main trouble is having to update the references and event triggers, when iterating on a prefabbed canvas which is present on multiple scenes. Can you elaborate a little on how Unity 5 improved things for you? Cheers!
I had a canvas full of UI elements I was using for a menu. I was trying to copy it in between scenes and all of the script fields in canvas were being cleared out, meaning the references weren't being carried over. With Unity5, I'm able to copy canvases between scenes without losing references. That is why I don't need the solution in the answer anymore.
Answer by skylem · Jan 13, 2015 at 08:32 PM
You could write something to store temporary data as you transition between scenes im not sure what parameters your losing upon scene transition but you Could use PlayerPrefs.SetString then load the string on next scene and if it equals certain parameters then u apply them to your new gameobject
If i wanted a scene to remember i've destroyed something when i leave the scene i would store a Bool for isDestroyed then reload it when i re enter the scene. There is most definitely alternatives and probably even better methods i just thought id mention how i've dealt with this in the past.
there is also the DontDestroyOnLoad
Thanks for the answer! but I'm talking about getting objects copied between scenes in the editor, not during the actual running of the game. I'll update the question.
Your answer
Follow this Question
Related Questions
Objects that appear in the editor's game view do not appear in the game build 0 Answers
How can I Select/focus the SceneView in Editor? 2 Answers
Gizmos.GUIDrawTexture - draw texture below? 0 Answers
Editor plays all sounds in the scene even when game is stopped 0 Answers
Is it possible to override SceneView / AnimX Private Types? 0 Answers