Optimization The Animation Trigger System | Tech Discussion
In a previous blog post I explained how I replicated Unity’s Animator.SetTrigger() functionality in UE4. The way I accomplished this was by creating an actor component attached to the player blueprint called AnimationTriggers which contained a publicly accessible boolean for each animation the player blueprint might wish to trigger (Attack/Roll/StepBack/etc.). The player’s animation blueprint then checked these booleans every frame to see if they had been set to true. If they had been, then the animation blueprint would respond to the trigger and try to play the desired animation using its animation state machine and also reset the trigger back to false.
Here are some diagrams from showing the design of this system:
[From our tech document]
[From our tech document]
[From our tech document]
The problem with this design, however, is that the animation graph wastes a lot of CPU time by checking every frame if any animation triggers have been set.
It would make much more sense if these triggers were only set when the actual triggering occurs!
I learned about a feature in Unreal I was not previously aware of which provided an excellent solution to this problem: the blueprint interface. Blueprint interfaces can be created by right clicking in the content browse and choosing Blueprints/Blueprint Interface.
Blueprint interfaces only provide function declarations for child blueprints to implement. So I then created a blueprint interface BPI_AnimationTriggerable, and set my AnimBP_MythicismPlayer to implement this interface. This interface can then replace the AnimationTriggers component on the player, allowing triggers to be called directly rather than wasting time on if-checks every frame.
Here’s an example of the refactor…
Before:
After:
So there you go: a simple optimization to triggering animations in UE4 that helps tidy up the implemenation.
Author: Reilly da Silva
Files
Get Mythicism
Mythicism
Status | In development |
Author | Arcane Studios |
Genre | Action |
Tags | 3D, Action-Adventure, Dungeon Crawler, Fantasy, Singleplayer, Third Person |
More posts
- DOT Particle Effect Not Working In Release Build | Tech DiscussionJun 24, 2022
- Tech Discussion | Boss Post MortemJun 23, 2022
- Ranged Enemy Aiming Problem | Tech DiscussionJun 17, 2022
- A Problem With Blade Trails | Tech DiscussionJun 10, 2022
- Tech Discussion | Boss BehaviorJun 10, 2022
- How To Edit Animation Sequences (Additive Layer Tracks) In UE4 | Tech DiscussionJun 03, 2022
- Tech Discussion | Altar System and Player levelingMay 23, 2022
- Tech Discussion | Save SystemMay 23, 2022
- Adding Varied Footstep Sounds | Tech DiscussionMay 15, 2022
- Designing A Souls-like Block Mechanic In UE4 | Tech DiscussionMay 14, 2022
Leave a comment
Log in with itch.io to leave a comment.