Game Development Community

When to use T2dSpawnObjects over T2dSceneObjects in TXB

by rwillis · in Torque X 2D · 11/04/2007 (5:12 pm) · 0 replies

I place a T2DStaticSprite in TXB for each enemy, but I often find I need to change something for all of them, which means I need to click on every T2DStaticSprite and change what's needed, which is time consuming. It seems a solution for this is for me to use a T2dSpawnObject for each of them. Then all I have to do is click on the SpawnTemplate object and when I change it all the T2dSpawnObjects that I placed are changed automatically. BUT when I change all my enemies to T2dSpawnObjects I can no longer get a reference to their component. So are we not able to get references to the component object of a SpawnObject?

If my enemy objects are set as T2DStaticSprite then everything works fine, but if I set them to T2dSpawnObjects I get a null reference errror at "component.AIEnabled = true" below. Thanks.

T2dSpawnObject enemy01 = TorqueObjectDatabase.Instance.FindObject<T2DSpawnObject>("enemy01");

component = enemy01.Components.FindComponent<EnemyComponent>();
component.AIEnabled = true;

When should I use T2dSpawnObjects over T2dSceneObjects for placing enemies in TXB (well, and in general)?

Edit:

When I GetNumComponents() on "enemy01" it returns 0. It looks like I can't use this as a reference to the spawned object. Or can I? So if I want to spawn an object and then change a variable in that spawned object's component through a reference to the component, how would I go about doing that?