One new scene object, adds two?
by Phillip O'Shea · in Torque Game Engine · 02/24/2008 (5:44 pm) · 2 replies
I've created a new type of object with the following code:
When I create the object in the game, it will add it nicely, at least on the surface. The "onAdd" function is called twice generating two different ID's. One object holds the shape of the object and the other is the actual object (%object = new PuzzleShape(DatablockName); ).
Am I doing something wrong for my object creation?
//-----------------------------------------------------------------------------
// Puzzle Object
//-----------------------------------------------------------------------------
#ifndef _PUZZLEBASE_H_
#define _PUZZLEBASE_H_
#ifndef _SHAPEBASE_H_
#include "game/shapeBase.h"
#endif
//----------------------------------------------------------------------------
struct PuzzleBaseData: public ShapeBaseData
{
typedef ShapeBaseData Parent;
//
PuzzleBaseData();
DECLARE_CONOBJECT(PuzzleBaseData);
//
static void initPersistFields();
};
//----------------------------------------------------------------------------
class PuzzleBase: public ShapeBase
{
typedef ShapeBase Parent;
protected:
PuzzleBaseData* mDataBlock;
protected:
//
bool onAdd();
void onRemove();
bool onNewDataBlock(GameBaseData* dptr);
public:
//
DECLARE_CONOBJECT(PuzzleBase);
static void initPersistFields();
//
PuzzleBase();
~PuzzleBase();
};
#endif
// Part of the CC file
bool PuzzleBase::onAdd()
{
if(!Parent::onAdd())
return false;
addToScene();
if (isServerObject())
scriptOnAdd();
Con::printf("PuzzleShape: %d", getId());
return true;
}When I create the object in the game, it will add it nicely, at least on the surface. The "onAdd" function is called twice generating two different ID's. One object holds the shape of the object and the other is the actual object (%object = new PuzzleShape(DatablockName); ).
Am I doing something wrong for my object creation?
About the author
Head of Violent Tulip, a small independent software development company working in Wollongong, Australia. Go to http://www.violent-tulip.com/ to see our latest offerings.
#2
02/24/2008 (7:58 pm)
I changed it from ShapeBase to StaticShape and it works the way I would have imagined it to.
Torque 3D Owner Robert Blanchet Jr.