Game Development Community

onAdd() before onLevelLoaded() where is scenegraph?

by Mirko Topalski · in Torque Game Builder · 07/28/2009 (6:32 am) · 6 replies

I have enemies in my game that can spawn at any moment, and some of them are already on the stage when level loads.

My problem is, i need to mount multiple objects on my enemies in onAdd() event. But when i try to create those objects, it seams that they cant find scenegraph, since onAdd() is executing BEFORE onLevelLoaded() function where all objects (and finally scenegraph, i suppose) are created.

Am i wrong? And is there any way i can define scenegraph for those dynamically created objects in onAdd() callback?

#1
07/28/2009 (6:45 am)
It just sounds like you need to call it after the onLevelLoaded() function. What's the problem with that?

EDIT: I don't see any onAdd() function in the list of callbacks. Is it your own function? If so, no function should really come before onLevelLoaded.
#2
07/28/2009 (7:26 am)
Can't you mount the dynamic objects onto the enemies in the enemy's onLevelLoaded? If you do that, you can use the enemy's scenegraph.
#3
07/29/2009 (12:16 am)
Thats strange, there is no onAdd() callback in docs, but i saw they used that method in some old tutorial. The callback works just fine.

But, as i said, this callback is calling as soon as the object is created, even BEFORE the entire level is created. And i want to use this method since
- some enemies are already on he stage
- many others will be created later during the gameplay
Thats why i cant use only onLevelLoaded() callback.

I guess this is a question for TGB developers, since onAdd() is not documented function call.
#4
07/29/2009 (5:36 am)
I still don't understand why those reasons preclude using onLevelLoaded, but if they're in the level anyway, can't you still grab the scenegraph with getSceneGraph() during onAdd? I've never had a problem like this and I've done tons of dynamic object creation on level objects.

My guess is that either you should be using onLevelLoaded on all your in-level objects or the scenegraph can be grabbed onAdd.

Hmm, let me know if any of that helps - I can probably try some things out if it doesn't :)
#5
07/29/2009 (5:38 am)
Or, are you using onAdd instead of onAddToScene? I think onAdd isn't documented because it's not as useful as onAddToScene - which should have the scenegraph.
#6
07/30/2009 (1:43 am)
Yea, thet worked just fine for me. Thnx.
It seams that onAddToScene is calling AFTER the entire level is loaded, therefore i can call scenegraph.

Thnx again ;)