In the previous two posts, I created the action bar and enabled drag and drop on it:
- How to make a great action bar in Unreal Engine (unreal-mmo-dev.com)
- How to give your Action Bar Drag & Drop in Unreal Engine (unreal-mmo-dev.com)
Now I will start to actually create a skill implementation for the game, I will begin with two basic skills for:
- fireball: after channeling, hurl a travelling fireball at a target
- basic heal: after channeling, instantly heal a target for a certain amount
There were multiple things for me to consider and this only caters for partial implementation:
- request to begin casting skill
- initiate channeling
- receive response to stop channeling skill
- begin skill animation and effects
As usual, the backend server that’s used can be found in GitHub here.
Creating a new Skill Base object
I will create skills as objects in the game, such that they contain all the information you need to start activating the skill.
Other skill objects will have this Base Skill as the parent class, so it should contain all the foundation requirements for a skill.
All or most of the skills will require the following variables:
- Skill definition, including name, description etc
- Activating Actor: the actor which is activating the skill, whether its a player or mob.
- Target Actor: Skills will not always require a target actor, however most will.
- Icon: Icon is used to represent the skill in the action bar
This list may grow with time, but its a starting point for now. Also the Skill structure encapsulates most core information I need.
For now, its definition is:
Skill Activate function
This function is actually mainly working as an Interface. Also, not all skills will require me to Start Attack Cast Animations.
I will likely create several additional base classes for skills, which will define their own cast animation definitions. For now however, as I only introduced 2 basic skills, this is sufficient.
For reference, this StartAttackCastAnims function simply switches a Boolean in the player blueprint which will be watched in the animation blueprint.
Fireball definition
The fireball definition is relatively simple, it’s catered for processing on the client side.
For reference, the art and animations are used from this asset pack: Fantasy RPG VFX Pack in Visual Effects – UE Marketplace (unrealengine.com)
You should be able to use other packs as you like.
You can see from the blueprint above, I spawn a particle actor relative to my casting actor with a transform offset. In future, I would make it relative to specific bones (from the hand).
Here the particle actor is essentially a mesh with a particle system and projectile movement.
The look and feel you can customize as per your requirements.
I disabled the collisions on this actor because I will want this fireball to just go directly through to the main actor – even past trees etc. This will be by design.
The Fireball will have homing projectile movement. I will want to check whether I’ve reached the target and I will just do that by checking whether the distance between this projectile and target is within a certain threshold.
When it is, I will destroy the fireball actor and spawn the expected explosion.
I also have the function to ‘Lock on to’ target:
Heal skill
The heal skill follows similar convention to the Fireball, however its a little different.
The heal skill will not create a projectile which will travel towards a target. It’s going to appear relative to the target actor, specifically from the bottom.
I created a new custom event on my actor base class:
To be honest, I’d like to add fade effect to these skills, rather than completely disappear – but there’d be a bit extra steps to do that so will cover it later.
Finding Skill object by skill ID/Name
Previously, I did lookup of skill icon based on skill ID/name. I’ve refactored to simply get the skill object through this means. This means we’d create a simple structure to represent the skill and create the Data Table to find the skill.
SkillMap structure:
Skill Table:
This means that I can use the generic ‘Skill’ to reference my core objects and use the ‘Activate’ function similar to a template while pointing to the correct instances of the skills.
Activating the skill
We covered these steps from the creation of the action bar.
Each action bar is associated to an input action
So as we can see, we request the server to activate the skill based on the skill name. The castor ID is implicit (through self), though later we can add that explicitly, which will help when we have support for friendly units. We provide the target which is the selected target from the Actions Component.
The Java backend server then does the following:
- Sends push to start actor channeling
- Creates async workers to wait channel cast time
- When cast time completed, send request to stop channeling and sends another request to initiate skill
- part of initiate skill, it will process to activate effects, such as damage and heal
So our Unreal Engine client needs to process these responses
Processing server responses
From our server we can receive a few new commands:
Here’s how I currently process them.
In each case, I want to first find the relevant actor based on actor ID. This returns me the object representing that actor, in my current case its always the player but it can be proxies or mobs in future.
For starting / stopping channeling, I’ve simply introduced a new Boolean in my character blueprint, ‘isChanneling’. This will be used in animation blueprint and I will show how that’s used soon.
To initiate skill, we already saw the ‘Activate’ functionality from the Fireball and Heal and this is how we can map it.
For reference, this is how I populate the Skill Map using the Data Table.
Animation BP for channeling
I wasn’t sure where I wanted to put the animations for channeling and activating the skill. I may still potentially put it into the skill Object to give more control over the options and variety.
This means there isn’t 1 best way for all projects and it will likely depend on your requirements.
So for now, I specify the channeling and cast animations in my animation blueprint.
First, find your animation BP, you can do this from your character BP by locating the anim class. You can also just confirm that you’re using an animation blueprint in the first place.
In the animation blueprint, I will add two new states for:
- Channeling
- Start Cast Attack Animations
To enter the channeling state, simply need ‘is Channeling’ to be true. And to exit, it has to go to false.
To start the cast attack animations, similarly, ‘start cast attack’ needs to be true.
The state will exit when the animation is basically complete.
Inside the channeling state, simply play the animation sequence for channeling.
And likewise for cast attack animation, we play the animation:
Animation notify
For the cast attack animation, I added a notify to reset the animation sequence.
You can open up your animation sequence, right click and click ‘add notify’ and select ‘new notify’.
I called it ‘CastAttackStarted’.
Now if you go back to your Animation Blueprint, you will be able to handle these custom events.
As you can see, I create a new graph where I will handle my custom animation notify events. Here I searched for ‘CastAttackStarted’ animation notify and I will simply reset the ‘Start Cast Attack’ when its called.
Conclusion
I am now able to start displaying the activated skills in my UE client, using the generic skill model.
When I start a fireball, I will create new projectile class and set the homing target for it to chase.
The damage and channeling is processed by server which periodically sends updates to the client.