Game Development Community

TGB 1.5.1 Clone and Group problem

by David House · in Torque Game Builder · 11/10/2007 (5:19 am) · 1 replies

When you clone an object, the code is not setting the mGraphGroupMask member variable at all. So what happens is that cloned objects default to Group 0. If you are trying to use the Collision Group stuff, it will not work as you expect. The simple workaround is to set the Group manually after the clone. Here is an example of my clone method:

function createClone(%this,%name,%pos)
{
	eval( "%newEnemy = " @ %name @ ".cloneWithBehaviors();");
	%template = %newEnemy.getBehavior("TemplateBehavior");
	%newEnemy.removeBehavior(%template);
	%newEnemy.position = %pos;
	%newEnemy.GraphGroup = "2";
	%newEnemy.onAddToScene(%this.object.scenegraph);
}

If you look at the setGraphGroup function in t2dSceneObject, you find this line:
// Set Group Mask.
    mGraphGroupMask = BIT( mGraphGroup );

But in the copyTo method, mGraphGroupMask is not being copied or set. So your cloned object goes to group 0 by default.

#1
11/17/2007 (6:28 pm)
Clone takes an optional bool parameter which will copy all fields to the cloned object. I haven't tested if this includes graphgroup, but it might, try:
%objClone = %obj.clone(true);