- Home /
Question by
Aubrey-Falconer · Jan 07, 2012 at 04:19 AM ·
gameobjectloadlevel
Creating a GameObject fails directly after Loading a Level
This behavior puzzled me quite a bit 'till I figured out what was happening, so I thought I'd document it in the hope of saving someone else the trouble of troubleshooting.
Here's the code I created that enabled me to isolate this issue - ObjectSpawner.js: It should spawn Temp1, Temp2, and Temp3 - but even though Temp2 seems to spawn correctly it never appears in Unity's scene hierarchy.
function Start () {
var temp1 : GameObject = new GameObject("Temp1");
DontDestroyOnLoad(this);
DontDestroyOnLoad(temp1);
Application.LoadLevel("Scene2");
Temp2();
}
function Temp2 () {
var temp2 : GameObject = new GameObject("Temp2");
print(temp2.name); //It looks like it exists...
Temp3();
}
function Temp3 () {
yield;
var temp3 : GameObject = new GameObject("Temp3");
}
Comment
Best Answer
Answer by Aubrey-Falconer · Jan 07, 2012 at 04:21 AM
Question contains answer. If I should be posting questions I answer myself somewhere else, please let me know.