Game Development Community

Deriving Objects from ShapeBase

by Juan Aramburu · in Torque Game Engine · 03/13/2006 (6:01 pm) · 1 replies

I am trying to add functionality to the engine by modifying the source code, and it seems that for what I'm doing the most natural thing would be to extend the ShapeBase class. I have done so, but when I attempt to place an object of the derived type into the game, it doesn't show up. If I change the derived object, to make it a child of TSStatic (as opposed to ShapeBase), then it shows up. I have been unable to find any information about sticking a derived class like this into the game, any help would be much appreciated.

#1
03/21/2006 (11:24 pm)
I'd personally refer to StaticShape as a basic example of how to derive an object from ShapeBase, or maybe Item. From the sounds of it though, what you're missing is a call to addToScene() in yourObject::onAdd. Basically, yourObject::onAdd should look something like this:
bool StaticShape::onAdd()
{
   if(!Parent::onAdd() || !mDataBlock)
      return false;

   //Custom setup stuff goes here... whee...

   addToScene();

   if (isServerObject())
      scriptOnAdd();
   return true;
}

yourObject::onRemove should look something like this:
void StaticShape::onRemove()
{
   scriptOnRemove();
   removeFromScene();
   //Custome remove code goes here
   Parent::onRemove();
}

That should be enough to get a basic renderable object derived from ShapeBase. Let me know if you've already one that or if this doesn't work.