Game Development Community

Clearing a deleteNotify

by Daniel Buckmaster · in Torque Game Engine · 10/28/2009 (12:36 am) · 4 replies

What happens if I store a pointer to an object, then call deleteNotify(ptr), then subsequently set ptr = NULL? Of course, the notification will still be called when ptr is deleted. Is there any way to stop me being notified when ptr is deleted?

I ask because my AI senses need to know if an object they can sense has been deleted. However, before the object is deleted, they might move out of range and forget about the object, in which case we don't really care whether it's deleted or not. I guess the easy way would be to not bother with deleteNotify, and just check if the pointer is valid whenever the character wants to reference that object.

Or I could just ignore this, since it won't cause any problems - onDeleteNotify will just not find any contacts with the right pointer to remove. But I don't like the idea of AI characters being notified when any object they've ever encountered is deleted.

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
10/28/2009 (1:57 am)
I believe what you're looking for is clearNotify().

They're not the most intuitively-named functions in the world -- you've got deleteNotify(), clearNotify(), removeNotify(), and freeNotify(). They all sound pretty similar. But clearNotify() is the one that's the opposite of deleteNotify().
#2
10/28/2009 (3:34 am)
I thought that would be i, but this comment in SimBase made me cautions:
void deleteNotify(SimObject* obj);   ///< Notify an object when we are deleted.
   void clearNotify(SimObject* obj);    ///< Notify an object when we are cleared.
Should I ignore that? It seems to be suggesting that deleteNotify and clearNotify do a similar thing, but notify in different situations.

On the other hand, the C++ code doesn't seem to be doing anything similar in the two methods. I'll give it a go - thanks!
#3
10/28/2009 (1:02 pm)
setting the pointer to NULL does not delete the pointer,
it means *ptr is 0
pointer itself can still operate.

Eventually you can use something like this:
if(bool(pointer)) deleteNotify(pointer);
#4
10/28/2009 (8:22 pm)
No, sorry I worded that a bit weirdly. Setting ptr = NULL will not delete the object that ptr referred to previously, I was just meaning that I wanted to forget about the object. But after having called deleteNotify(ptr), even if I don't want to know anything more about it, onDeleteNotify will still be called when the actual object ptr used to refer to is deleted.

I wanted to find a way to 'cancel' a deleteNotify, if you will.