I have an actor that uses AActor::OnConstuction() to perform some setup. When the actor is removed through the editor, I would like to perform some cleanup. Is there an event I can use for this?
I attemped to hook OnDestroyed from the ctor, but it is not being invoked.
You may want to try using BeginDestory() rather than OnDestoryed(). BeginDestory() is called before the actor is actually destroyed where OnDestoryed() is called when the actor is destroyed, which may lead to issues depending on if the actor still exists when the call is made. You can bind your function as you indicated or you can simply call your function inside BeginDestroy().
Thanks. I think I managed to get it working, though it wasn’t very intuitive. Upon deleting the actor in the editor, BeginDestroy() only seems to be called for the transient placeholder instances that are created as you drag your mouse over the viewport to place the actor. After saving the level twice it will then be called for the non-transient instance.
Just for anyone else that sees this, when you use AddDynamic to register a callback, the callback must be decorated with UFUNCTION() otherwise it won’t be called.
More information would be necessary to fully understand your issue. Also, to prevent the details of your issue from being lost in this post, and to help others who may be having the same/similar issue, it would be helpful to create a new post. Please be sure to include the full call stack from the crash as well as the code you’re using to override the BeginDestroy() function.