How can I check if a pointer to actor was freed
Lets say that I have a class of fireball which holds the fireball target (actor type). In the tick function I am updating the fireball velocity direction to the target so if the target moves the fireball will keep track at it. The problem is - what if the actor was already destroyed and freed by the engine? lets say that the fireball was shot, and then the target died by another entity (whatever it is), so the destroy function has been called and the engine freed the actor. In this situation the fireball hold pointer (target) to a freed memory, and if it will try to call any of the actor functions the game will crash. How can I check if actor was freed?
I have thought about sending an event when the actor is dead before it gets destroyed, is it the best option?
asked Oct 11 '17 at 09:51 PM in C++ Programming
You can use a TWeakObjectPtr to hold the weak actor reference in your code.
Is it specifically designed for this sort of thing:
answered Oct 11 '17 at 09:56 PM
Jamie Dale STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here