Game Development Community

T3D 1.1 Beta 3 - SimObjects can't be added to group from onAdd method +fix - LOGGED

by Fyodor -bank- Osokin · in Torque 3D Professional · 03/30/2011 (9:07 am) · 1 replies

Build: T3D 1.1 Beta 3 Pro

Platform: Windows (+ Mac/Linux)

Target: Adding object to SimGroup via onAdd() method.

Issues: SimObjects (and any derived class) can't be added to group from its own onAdd() method.

The logic checks only if the object have SimGroup/SimSet it was created "inside":
new SimGroup() {
   new SimObject() {};
};
From sources:
..//skipped
                     // Otherwise just add to the requested group or set.
                     if(!Sim::findObject(groupAddId, grp))
                        Sim::findObject(groupAddId, set);
If it goesn't find SimGroup (as grp declared as "SimGroup *") it will automatically add the object to the rootGroup, and it doesn't check if the object has been added to any group during it's initialization process (via onAdd method).

Suggested Fix:

engine/source/console/compiledEval.cpp

Find function:
const char *CodeBlock::exec(U32 ip, const char *functionName, Namespace *thisNamespace, U32 argc, const char **argv, bool noCalls, StringTableEntry packageName, S32 setFrame)

Inside
case OP_ADD_OBJECT:
block replace this code:
..//skipped
               // If we didn't get a group, then make sure we have a pointer to
               // the rootgroup.
               if(!grp)
                  grp = Sim::getRootGroup();
..//skipped
with this one:
..//skipped
               // If we didn't get a group and it wasn't assigned inside onAdd(),
               // then make sure we have a pointer to the rootgroup.
               if(grp)
                  grp->addObject(currentNewObject);
               else if(!grp && !currentNewObject->getGroup())
                  Sim::getRootGroup()->addObject(currentNewObject);
..//skipped