x


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?

more ▼

asked Jan 25 '12 at 11:33 AM

Marnix gravatar image

Marnix
1.3k 21 31 45

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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.

more ▼

answered Jan 25 '12 at 11:56 AM

Lo0NuhtiK gravatar image

Lo0NuhtiK
3.5k 1 9 39

@Lo0NuhtiK 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.

Jan 25 '12 at 12:02 PM Marnix

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?

Jan 25 '12 at 12:07 PM syclamoth

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.

Jan 25 '12 at 12:12 PM Marnix

          

Jan 25 '12 at 12:15 PM Lo0NuhtiK
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2087
x263
x106

asked: Jan 25 '12 at 11:33 AM

Seen: 635 times

Last Updated: Jan 25 '12 at 12:15 PM