For this project I created a simple fireball ability using Unreal Engine 5.1. The goal for the project was to practice what I learned in Tom Looman’s C++ course but also venture a bit further into new topics such as Niagara, Metasounds and animation.
The video below shows the fireball effect in action. After the video there’s some more explanation what is happening.
We are controlling a mage which performs an attack animation upon pressing Q on the keyboard. As soon as the attack animation is started a small fireball is spawned in the mage’s hand to show how the bigger fireball effect is casted. Then at the right point in the animation the bigger fireball effect is spawned and shot forwards. Any enemy it hits, will be damaged and a fireball explosion effect spawned. Enemies out of range should not get hurt or touched by fire.
Most of the programming has been done in C++. I think much of it could have also been done in Blueprint but the goal was to practice using C++ and Unreal Engine’s gameplay framework.
We have two characters one for the mage which is possessed by the player controller and one for the enemy. Currently no AI logic is connected to the enemy character yet. In both characters the Attribute Component is responsible for keeping track of how much health the character has. It also exposes ways to change health and subscribe to an event to get notified of health changes (e.g. to display a UI).
The Action Component contains a list of all actions this character is capable of using. We add a reference to the Fireball Action so we can activate it if the player presses Q on their keyboard. The Action Component and Action classes are part of Tom Looman’s Action system which is a much simpler and more basic version of Epic’s Gameplay Ability System (GAS).
Every action has a start and stop method which will get called if the player throws a fireball. Upon starting the action the attack animation montage is started. I really wanted to make use of Animation Montage Notifications. However, I didn’t find a way to use notifications from C++. That’s why the part of controlling the animation montage is done in Blueprint:
We start the animation montage. Then we listen for notifications. If the
Starter notification fired, then we spawn the Niagara effect Fireball Starter Effect in the right hand, to show that a fireball is forming.
Next, once the animation progressed far enough so the
LaunchPosition notification spawned then the mage character is in the correct position to spawn the projectile.
At this point we call the C++ function
SpawnProjectile from Blueprint to give control back to C++.
Right after spawning the projectile we start playing the fireball in-flight sound via the attached Fireball Audio Component. We also start the Fireball Niagara effect. Next, we start two timers, one for making sure the projectile stops as soon as the Niagara effect stops advancing and the other one to kill the projectile actor after it’s not needed anymore. Note: there might be a better way to do this - if you know of one, let me know.
Finally, we also register to OnComponentBeginOverlap for the Sphere Component. If an overlap is triggered, we check if the actor which got hit has an Attribute Component attached. If so, then we use it to apply damage and also spawn the Fireball Explosion Niagara effect. In addition to the Niagara explosion effect we also spawn an explosion sound close to the location where the actor got hit.
This is actually my first time working with Niagara, so it was very exciting. I used the effect NS_Mage_Fireball from the pack RPG FX Starter Pack by tharlevfx.
However, the fireball effect was just the fireball flying through the air, but I also needed effects to show how the fireball is casted and also what happens if it hits an enemy.
For both use cases I used the initial fireball effect as a base and modified it to get separate Niagara systems for casting the fireball and also one for when it explodes:
So far I only used the legacy sound system in Unreal Engine. Therefore, it was my first time trying Metasounds and it was very much fun to play with it.
I used two metasounds to give the fireball effect more life:
- Fireball flying through the air
- Fireball explosion as it hits an enemy
For both sounds I used a wave sample from the free marketplace freesound.org. I then used those sound samples and applied various effects to it. I mainly wanted to change the playback speed and add some more distortions to make it more impactful.
In the end I also added randomness to both sounds by varying the pitch and distortion levels at random every time the sound is played.
Here are the thirdparty assets I used:
- Mage: Modular Wizard in Characters - UE Marketplace
- Enemy: Orc in Characters - UE Marketplace
- Mage Fireball effect from RPG FX Starter Pack in Visual Effects - UE Marketplace
- Fireball swoosh sound Freesound - “JM_FX_Fireball 01.wav” by Julien Matthey
- Fireball explosion sound Freesound - “fire_explosion.wav” by ReadeOnly
This project was a blast to work on. It’s always scary at first if you’re moving from a course to implementing something yourself but it’s also very rewarding once you achieve the goal.
There are still many areas that I’d like to dive deeper into in the future like networking, gameplay ability system, more animation and also UI. I’m looking forward to tackle these topics in future posts.
If you have any suggestions, questions or feedback consider leaving me a comment.