Why does calling a AddOnScreenDebugMessage causes Editor to crash when it is called inside BeginDestroy?

Hello. I’ve been trying to print a message on screen to see when the Uobject is about to be garbage collected. However it seems like I cannot do this. Is there any other way to (just for development purposes) get notified when the object is about to be deleted?

Try this: Running C++ code upon an actor's destruction? - World Creation - Epic Developer Community Forums

Ah OK. Is there a chance your logging call is bad? Seems weird that you can’t log at that point. Also, why can’t you call out to an external object that can handle logging the message? If it’s just something about logging that will never work within BeginDestroy, then I suggest using a queue to buffer the log strings. Add to the queue from the BeginDestroy and then print out the items in the queue in your GameMode’s Tick function (or a looped timer).

However, I’m not talking about an actor, only about Uobject.
OnDestroyed is for actors only if Im not mistaken.

Hi,

Are you also calling Super::BeginDestroy() inside the overridden BeginDestroy method? The editor will crash if you don’t call it’s parent method. Just to be safe, try putting it as the last statement in there.

Hope this helps.

Because this is not an empty interface method but a virtual function that you’re overriding. Many of these overridable methods have their main functionalities implemented in their base classes. UE4 allows you to expand these methods and add your own functionalities but without a call to the parent method, UE4 cannot properly execute them, hence it will crash!

Thank uuu ! :slight_smile: Calling it at the end of BeginDestroy function stopped engine from crashing! :slight_smile:
Thanks, although I do not understand why should I call the parent function. :confused:

Yeah. Always call the super unless it’s empty or you’re sure it’s unneeded. And my lesson for the day (in more than one case) is to stop assuming that what’s being asked is the right question. Good catch, V.

Thanks, @anonymous_user_64f7311b :wink:
Yeah… some questions here can be vague and misleading, especially if they don’t provide any code or blueprints!