Game Development Community

RegisterObject Question

by William Todd Scott · in Torque Game Engine · 11/10/2005 (8:30 pm) · 5 replies

Hey All,

I am a bit confused with respect to the registerObject function for SimObjects.

I created a class in C+ that derives from SimObject so that my objects would be accessible via script. I create an instance of my object in C++ and I am able to get it via a ConsoleFunction and I can call methods on the objects.

So, whats my problem?

My problem is that I never called RegisterObject on the instance. So, I am not sure why everything is working. Specifically, I use the following console function to retrieve the object in script and I am not sure why the call to getID() is working.


ConsoleFunction(getMessageManager, S32 , 1, 1, "getMessageManager()")
{
	myClass* pInstance = myClass::getInstance();
	return pInstance->getId();
}

If I don't need to call register object in the case I outlined above, then when is it necessary.

I hope this is understandable!

Thanks for any help.
Todd

#1
11/11/2005 (6:36 am)
You mentioned that you "create an instance of my object in C++"--how specifically do you do that? You might be doing something that inherently is registering the object for you (although quite honestly that's doubtful, unless you are actually creating it in script and don't quite realize it!).

You are correct in your implication that getId(); shouldn't work without being registered...try using a Sim::findObject() on the index number that was returned.
#2
11/12/2005 (7:55 am)
Thanks Stephen!

Armed with the knowledge that I wasn't completely nuts, I quickly found what was going on. You were correct, the register object was indeed happening...


One followup question, is it safe to put the registerObject and unregisterObject calls in the constructor and destructor? Would this cause problems if the object is created in script?

Thanks again for the help.
Todd
#3
11/12/2005 (10:52 am)
Yes, that would cause some major problems if the object was created from script.
#4
11/12/2005 (10:55 am)
Ok, thanks.

Todd
#5
11/02/2010 (7:51 pm)
Cool, problem solved