Is there a way to know the reason an Actor has been destroyed ?

I have an actor class that has to perform certain operations when destroyed in the editor, so I’m overriding AActor::Destroyed for that.

The problem is that, for some reason (I think it’s because it includes certain headers where there are some FStructs declared), every time I hot reload my game module, Unreal reinstantiates all the actors of this class and calls Destroyed() on them.

Is there a way to know why an actor has been destroyed? So I can ignore Destroyed() calls if they are generated from a Hot Reload.

is probably what you want unless you specifically need destroyed

The problem with EndPlay is that only works at play time, not in the editor. Moreover, EEndPlayReason doesn’t have a specific case for Hot Reload.

I found a workaround by subscribing to GEditor->OnObjectsReplaced(), looking for the objects of the class I’m interested in and setting a bool property as a flag to know if the object is being hotreloaded.

But It requires to include the UnrealEd module as a dependency and looks kind of dirty anyway so I’m not really happy with it. Hopefully there’s a better solution.