Destroy() doesn't make reference to nullptr

I am trying to spawn an actor asynchronously using a TSoftClassPointer. I cache the spawned actor in an instigator actor for later use, but when I do Destroy(), the reference of the spawned actor is not nullified in the instigator actor.

Does using a Async Loading or TSharedPtr complicate nullifying pointers?

When are you looking at the member on the instigator? Immediately? If so, it won’t be cleared until the Garbage Collector comes through and actually frees up that object.

Is your cache on the instigator a UPROPERTY? if not, it won’t be cleared because the GC can’t clear something it doesn’t know about.

Not in a case like this.

Okay, so it turns out that I wasn’t waiting long enough for the GC to come through.
I suppose the only solution would be to manually mark it as a nullptr?

I think that if you switch to using IsValid instead of doing nullptr checks, it would return false for Actors that you’ve called Destroy on. But I’m not 100% on that.

Or you can manually set the pointer to nullptr after you call Destroy.

Ah, perfect! IsValid() seemed to do the trick. Didn’t know I could do that… Thank you for the suggestion:)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.