Game Development Community

SimObject referencing

by Richard Andersson · in Torque Game Engine · 06/13/2007 (6:52 am) · 2 replies

Just a quick question. When am I supposed to use the SimObject referencing tools (registerReference/unregisterReference) and SimObjectPtr? What happens if i don't register my references? Could it create problems? From what I can tell, not much should happen but maybe I am missing something.

#1
06/13/2007 (10:36 am)
If you are keeping a reference (pointer) to an object outside of the scope of a single execution call frame (such as a new class that has a pointer that stores a reference to another object for example), then you should be highly considering using a SimObjectPtr.

The main benefit is that if the object you are referencing is deleted normally, all SimObjectPtrs will be "magically" made null. If you follow good programming practice and always check your pointers validity (myPtr != null), then you will never have a stale reference.

Register/Unregister reference is the same concept, but requires a bit more coding, and is for a more generic case. It's not used too often for most games.
#2
06/14/2007 (2:10 am)
I see. That's pretty cool, I should start using those :)

That's probably not what's causing my problems though... I'll start another thread.