AActor event for editor shutdown?

I need to do some cleanup in my custom Actor, or else things get messy. For an actual game I am handling this in EndPlay and that all seems to work fine. However in the editor, when you close the editor EndPlay doesn’t get called. Is there some other event I can use?

The first point-of-entry to stopping a game is Shutdown() in UGameInstance. You could possibly do a for loop there for all the actors you want to call the function on, or better yet send out a broadcast event that will automatically trigger a custom function in the actors? It should still be safe to do that so long as you call Super afterwards, since it also shuts the world down in there too.

Also might be worth just looking at that function in the engine code to see if it calls anything on the actors in a PIE session :slight_smile:

Hmm… I’m not sure if I can do a custom UGameInstance from a plugin? To be clear I am not referring to PIE, that works fine. I mean just the editor itself. When you drag out and place an instance of my custom actor, it generates a bunch of components, some arrays and maps, and data. If I then just exit the editor without first deleting that instance, none of my cleanup gets called and the editor code causes an exception. I’m not entirely clear yet on where or why but it seems to be when it is cleaning up components. In PIE it works fine because EndPlay gets called.

Did you tried using Destroyed()?

EndPlay as equivalent of BeginPlay will only run on gameplay, destroyed should be called anywhere

Oh yeah… forgot about Destroyed()