DevLog: Implementing Death (Animations) - Violet Weathersby


This week one of my responsibilities was getting the unit (both player characters and enemies) death working. We already had the code for knowing when a unit was dead thanks to the health component, but the characters would continue moving and fighting. This solution was fairly straightforward, add in the code to disable collision and to get the AI controller to stop movement then unpossess the character. Where the problems started was with the animations.

For our project we are using Unreal Engine’s animation graphs. In the first week, I copied work from a previous project where there is a movement state that transitions into a death state when the character dies. However, in that project the actor was destroyed as soon as the death animation was complete. In this project though we wanted to have a variable that controls how long the body remains until disappearing. Making this variable and timer went well, except that the death animation looped. 

To fix this problem I added a PauseAnimation function into the parent C++ class of all of the AnimInstance blueprints. This function would use a reference to the last “PlaySlotAnimationAsDynamicMontage” montage, which I also had to create, and call Montage_Pause. It wasn’t until just now that I saw the description of the Montage_Pause function.

It doesn’t need to have that reference to the current montage. Instead of creating a function the base squad class could just call AnimInstance->Montage_Pause(). (Probably, I haven’t actually tested it.)

So, even if it wasn’t the most efficient solution, the problem was solved, right? For the heroes, it was working, but when the orc enemies died the animation wasn’t playing. They would do this:

(which is the mesh’s default pose.) 

The source of the problem was in the animation graph. 

The Anim_Death is the name of the human animation asset specifically. The orc needs to be playing an animation called Anim_Orc_Death_Orc_Death. When I created the separate AnimInstance blueprints I created the human one, then copied it and swapped out the asset variables. 

There were two possible solutions for this problem. The first would be to go into each of the animation graphs and hard code the death asset into the death state like it was for the humans. The second was to remove the sequence player from the death state and to call PlaySlotAnimationAsDynamicMontage for the death animation in code like the attack and hurt animations. I decided to use the second solution since in general it’s best to avoid hard coding things. This way if we want to swap out the death animation, we can just change the variable instead of having to edit the graph. 

Once that code was implemented, I was done with this task, and our units were finally dropping dead properly!

Get Return to Divinity

Leave a comment

Log in with itch.io to leave a comment.