Animations and Animation Events
Written by Will Fox
2/23/2023
Hey everyone, Will again!
This week, my team and I finished up our - let's call it - pre-pre-pre-alpha build. We have a rough outline of what we want our game to look like, and we're ironing out the wrinkles in the basic mechanics. Jamari has gotten the possess mechanic working, Zak has the procedurally generated dungeon going, and Anthony finished up the UI for the title screen and pause menu. The thing that I did this week was get the AI to work as intended - such as not being able to shoot through walls. But, more importantly, the AI needs to look good, so ensuring the animations work correctly is a big deal. And that was one of the more significant issues I encountered this week.
Animation notifications were one of my most considerable resources to solve this issue. These notifications will execute events inside the animation blueprint so that you can sync up AI actions with logic. However, I ran into another problem working with these notifications. The "End Attack" notification wasn't executing. At first, I thought this was a scope issue or that I had set up the notification incorrectly. To test this, I created an event node for "Begin Attack" and "End Attack" and then attached a print node to them to see if they would print anything out. When I ran the game, the notifications were working exactly as intended, as the print nodes were getting hit. This was good to see since researching animations for Unreal on the internet can be pretty tedious. But, seeing that the notifications were working, I could move on to the next step, which was setting up a boolean to toggle when "Begin Attack" and "End Attack" were executed.
Before I continue, I want to take some time to describe my animation issue in more in-depth. Essentially what was happening was that the Lich AI would begin its attack animation but then would quickly stop and start idling or walking around. The reason this was happening was because there were no booleans or any logic keeping the Lich locked into the attack. Obviously, this made the Lich look super wonky and also introduced some other minor issues. And, since the attack animation gets interrupted, the "End Attack" notification never gets hit, which means the boolean being toggled by the event never gets switched.
Animation notification execution nodes
Now that I have explained the issue, here is how I solved it. The entirety of the issue was around getting the boolean that was being toggled by the animation notification. In Unreal, if you get a reference to a variable held within another class, it will only get the value of the variable once. So, if I create a reference to the Lich's animation blueprint and get the "Is Attacking?" boolean, that boolean being accessed through the reference will ALWAYS be whatever value the boolean was initially. This means that if "Is Attacking?" was false when it was accessed but then gets changed to true, the referenced boolean won't change to match it. So, instead of accessing the boolean through a reference, I created a function to access the boolean. Functions in Unreal MUST have an execution wire attached to them in order to execute. This means that the function will physically enter the other class and fetch whatever the current variable is. In short, using a getter function will return the most recent value of the variable.
Now that I had a method to receive the correct value of the boolean, I could now set up the Lich's animations to be timed with its attacks and ensure that it wouldn't be interrupted. I won't bore you with the details about how I set all of this up. It was essentially just a bunch of logic traps to make sure that if the Lich were currently attacking, nothing else would happen. Furthermore, I added some logic that would make sure that the Lich couldn't shoot the player through walls. If the player was out of sight of the Lich - or any enemy for that matter - the enemy would chase after the player until they lose interest or they see the player again. If the enemy does find the player and is in range to attack, they will attack.
To sum everything up:
Make getter functions to access variables from other classes
Slimegeon
Status | In development |
Author | zaklev |
More posts
- Finalizing the Skill Trees and the Missile TurtleMay 25, 2023
- Creating Modular UIMay 25, 2023
- Sword Reveal Over TimeMay 25, 2023
- Bug Fixes and CinematicsMay 25, 2023
- Fixing Pawn JittersMay 18, 2023
- Reworking the skill treesMay 18, 2023
- Reorder Save List by Date Last PlayedMay 18, 2023
- Possession, Lock-On Blips, and YetiMay 18, 2023
- Loading Screen and Lock On AdjustmentsMay 11, 2023
- Snowballs Destructive MeshMay 11, 2023
Leave a comment
Log in with itch.io to leave a comment.