Game Development Community

Abount removeFromScene

by Hugeone · in Torque Game Builder · 04/10/2006 (6:54 pm) · 1 replies

HI:
Here is my code.

function t2dSceneObject::onCollision( %srcCollisionObject, %dstCollisionObject,
%srcRef, %dstRef, %collisionTime, %collisionNormal,
%contactCount, %contactPoints )
{
%srcCollisionObject.removeFromScene( );
}

but , as soon as collision happen, program crash. I want to know when and where is safe to invoke removeFromScene( ) ?

regards
hugeone

#1
05/16/2006 (1:28 am)
I suggest that the method gets called at least one time for the first (src) collided object.. then you delete/remove it --- and the TGB calls the other onCollision method where the once %dstCollisionObject is now %srcCollisionObject.

There's a method called setCollisionActive which gets two options if the object should send and RECEIVE onCollision-Callbacks... maybe that's your problem?

Another solution maybe something like this:

function t2dSceneObject::onCollision( %srcCollisionObject, %dstCollisionObject,
%srcRef, %dstRef, %collisionTime, %collisionNormal,
%contactCount, %contactPoints )
{
%srcCollisionObject.deleteOnNextUpdate = true;
}

function t2dSceneObject::onUpdate(somewhat)
{
for(objects)
{
if(object[x].deleteOnNextUpdate == true)
{
%(object[x].removeFromScene( );
%(object[x].safeDelete( );
}
}
}

Hope you got the principle behind my idea.

Alex