Game Development Community

What is the isObject() Equivalent in C++ for SceneObjects?

by practicing01 · in Torque 2D Professional · 11/02/2013 (11:29 pm) · 4 replies

I can't use Sim::findObject() because it doesn't take a SceneObject. I just want to know if the SceneObject is valid.

#1
11/03/2013 (11:56 am)
I'm a bit confused, why wouldn't Sim::findObject work? Are you not looking to do something similar to this:

ConsoleMethodWithDocs(SceneObject, setCollisionAgainst, ConsoleVoid, 3, 4, (SceneObject object, [clearMasks? = false]))
{
    // Find SceneObject Object.
    const SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));

    // Validate Object.
    if ( !pSceneObject )
    {
        Con::warnf("SceneObject::setCollisionAgainst() - Couldn't find/Invalid object '%s'.", argv[2]);
        return;
    }
#2
11/03/2013 (5:21 pm)
I already did the above and stored the SceneObject pointer. As time passes by I can't rely on that pointer because deletion of the object won't modify that custom variable. I was looking for a function that would check the Scene objects and then I realized I could just loop through them myself. Which then made me realize doing that every tick wouldn't be a good idea so I resolved my problem a different way through TS, thanks anyway.
#3
11/07/2013 (9:01 am)
In, myClass.h
SimObjectPtr <SceneObject> myObject;
SceneObject * getMyObject(){return myObject.isValid() ? myObject : NULL;}



#4
11/07/2013 (1:00 pm)
SimObjectPtr (as Sorin pointed out is THE way to reference potentially transient SimObjects).

I use that is threaded code to track lists of objects that need data processed in a separate thread. Very good class.