Game Development Community

problems with certain behaviors after using spawnOnRemove

by Edwin Rivera · in Torque Game Builder · 03/21/2011 (6:22 pm) · 3 replies

Hello,

I have recently purchased Torque 2D both for a school project and for personal use. I am slowly getting the hang of behaviors but I have a slight problem with the spawnOnRemove behavior. Some of the objects I spawn unto the scene using this behavior, such as enemies, do not follow or execute any behaviors that they may have on them? For example, if I have enemy A, spawn Enemy B with the attach to path behavior when A is removed, B spawns, but he just moves away in any random direction. Why is this happening?

#1
03/21/2011 (7:13 pm)
How do you spawn the objects? What methods are used in the behaviours in question? If it's onAddToScene() or something like that and the object already is added before the behaviour is set, it won't work. Post some example code and datablocks if you can.
#2
03/21/2011 (7:23 pm)
Hey, thanks for your quick reply.

well I added the two objects to the scene using the editor. The first one (object A) was added with the take damage and spawnOnRemove behaviors. the second one (object B) I added it with the template behavior (so it is not active right away) and the attach to path. If I take the template behavior off the second objects spawns on the path no problem. But when it spawns as a result of the SpawnOnRemove from object A, it just floats away to any given random direction.
#3
03/21/2011 (7:39 pm)
I assume you are using the shooter example game.

I think what's missing is a call to <template object>.setEnabled(true). I don't think anything sets it to enabled unless you specifically ask for it, and all the template behaviour does is to disable an object. That means it doesn't update or render or anything.

You could probably just place object B outside the play area and attach it to the path manually when needed, rather than starting inactive. Unseen objects are not rendered and animated anyway. You'll need to dig through the documentation for paths and scripted mounting, probably.