BeginDestroy not getting called

I have some cleanup code that I want to execute when an actor is destroyed. According to the docs, I should do that in BeginDestroy. AActor::Destroy gets called but my BeginDestroy never gets called (until I exit the game). Am I misunderstanding the purpose of BeginDestroy or is this a bug?

Have you tried Derstroyed() instead?

	/** Called once this actor has been deleted */
	virtual void Destroyed();

BeginDestroy is inherited from UObject, so I’m not sure it will behave always correctly for AActors, but I have not tested it. Destroyed() works anyway…

Don’t think that will work. I have to do cleanup before the actor is destroyed because it has pointers to other actors that I need to destroy. If I wait until the actor is destroyed I won’t have access to those pointers anymore. I worked around it by making sure to explicitly clean up before the actor gets destroyed, but that’s not how it should work. It would also work to override AActor::Destroy and do my cleanup and then call Super::Destroy but unfortunately AActor::Destroy isn’t virtual.

I believe this is exactly what Destroyed() is for. It will be destroyed right after that, reference should still exist at that moment. At least give it a try :slight_smile: