Why is this timer causing Unreal Engine to crash?

In my game, if the Enemy’s (Health - DamageAmount <= 0), then it plays a death animation. At the end of the death animation, there is a Notify, which I am using in the EventGraph to call a function in C++ called DeathEnd, which pauses the Anims. Everything works perfectly without the timer, which waits three seconds then calls Disappear(), which only Destroy() the actor.

However, if I add the timer to the DeathEnd() function, the game crashes as soon as (Health-DamageAmount<=0), never calling Die() or displaying the UE_LOG I put there (which says “pre-die”).

I have the delay time, called “DeathDelay” initialized in the constructor, and all the parameters necessary are set in the enemy/character/weapon blueprints (sometimes they get reset to null, so I’m making sure they’re all set each time I play test).

I’m getting better all the time at de-bugging my own stuff, but this one really has me stumped. If you need any more information or screenshots, please let me know.

This is my cpp file with the death functionality for the enemy. The offending timer is commented out towards the bottom. Also note the UE_LOG that says “Pre-Die” is not being reached with the timer in my code, but “Take Damage” is being reached. As soon as the enemy should die, the game crashes:

The callback function for the timer just calls Destroy():

In the EventGraph for the EnemyAnimBlueprint, I’m calling the DeathEnd function from the AnimNotify, functionality is in C++ in first screenshot:

This is where the DeathEnd notify is, in the animation montage that I’m playing from C++:

Like I said, everything works perfectly if the timer isn’t being set, just after the enemy dies he stays lying there forever, so I would love to figure out why my timer is causing the game to crash.

By the way, this is the crash report. I’ve had this error before when I accidentally constructed two different components with the same name, but I don’t see how a timer is relevant to that, so I’m still stumped. Thank you in advance, I’m going to keep looking into it

I don’t know why you’re crashing, but the Unreal actor already has a “time left to live” property you can set, which will kill the object when that time expires. It’s built-in.

Thank you for your reply! I will definitely try that. I’m taking this course on Udemy and I’m still waiting for the instructor to reply to my question there, but this seems like a good work around.

MoveToTarget() is being called in your Enemy after it’s been destroyed.

Where do you see this? Enemy isn’t destroyed until the DeathEnd() function, which is never being reached before my game crashes. I have a function that checks if the enemy is alive, and I check if he is alive before I call MovetoTarget()

That’s the first line of the backtrace in the crash report. Enemy.cpp:261

It looks like you’ve got some delegate listener that needs to be disconnected when destroying, otherwise CombatSphereOnOverlapEnd is called after the actor is destroyed

1 Like

Thank you! the Crash report was so much to look at, I got overwhelmed and wrote it off, but it turns out it was pointing to this line in Enemy.cpp: TArray PathPoints = NavPath->GetPathPoints();

I used it for debugging earlier, but I wasn’t doing anything with it anymore, and I guess the engine was mad about it! I commented that line out and everything is fixed. Thanks again :slight_smile:

1 Like