- Home /
Loading a level and getting all new gameobjects
Is it possible to load a Scene with Application.LoadLevel
and get all newly added GameObjects that have been loaded?
Answer by Lo0NuhtiK · Jan 25, 2012 at 11:56 AM
var allObjects : GameObject[] ;
function Awake(){
DontDestroyOnLoad(gameObject) ;
}
function OnLevelWasLoaded(){
allObjects = GameObject.FindObjectsOfType(GameObject) ;
//debugger->
for(var i : int = 0 ; i < allObjects.length ; i++){
Debug.Log(allObjects[i].name) ;
}
//could also just watch the inspector panel populate instead of looking at debug
}
Throw that on some object in your scene, do what you do to go to the next level, and that should do the trick.
@Lo0Nuhti$$anonymous$$ Thanks, I already knew that I could do it by script, but I am looking for a function in Unity that can tell me exactly what is in the scene.
Yeah, I thought of this, but it doesn't take objects that are marked with 'DontDestroyOnLoad' into account. I don't think there is any inbuilt way of doing this. Just out of interest, what are you going to do with the information?
I am always trying to get the most out of the engine. If there is no way of doing it via the API, I will use the script as you suggested. But initially, I will always try and find a good call in the engine.