Training Livestream - C++ Q&A - June 27 - Live from Epic HQ

So long as you’re not using multithreading in an inherently unsafe way, you shouldn’t have to worry about something being destroyed since your last validity check, so long as you’re not relying on checks made in previous ticks.

Anywhere you need to store a reference to an actor over multiple frames, I’d strongly recommend using a TWeakObjectPtr< AActor > in place of AActor* for your member variable/property. You can then do


if(MyActorPtr.IsValid()) { MyActorPtr->DoSomething(); }

The weak pointer will be updated by the garbage collector, that’s the only validity check you need to make. Do it at the entry point where you first need to access the actor; once you know it’s valid, you can be sure it will remain valid for the remainder of that scope, unless you cause it to be destroyed yourself.