GameplayAbilities and you

Hello reader, I request you to visit the wiki page based on this forum post instead of trying to follow steps and take information from here. Because the wiki page is more likely to be complete, up to date and maintained than this ol’ wall of text here, I have removed the guide that was once here for the time being.](A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums)

In case of questions I would recommend checking out the #gameplay-abilities-plugin channel on the UE4 Discord. I personally am not as active on here as I used to be, but the people on there are continuously picking on the plugin themselves and are generally helpful if you are in need of troubleshooting.

If you want to further your understanding of the more niche aspects of this system, I do recommend DamirH’s analyses, thoughts and ramblings on the other aspects of the system that have not been thoroughly covered here. It will be your bet for advanced insight into the system’s more niche aspects as well as discussions involving them, as the guide written here aims to be more of a simple introduction to the system and a step-by-step to get its core running, and I consider it to be more or less complete in this regard.

Will you marry me? :slight_smile: Thank you so much for this man i’ve been looking for a guide for months while trying to figure out the way to use this system.

That was the main motivation. I myself had been looking for a guide for a month or two until I actually found the sample project from Epic provided. I have no idea why it doesn’t show up on google or any search whatsoever anywhere, but someone on reddit just casually linked it like “oh btw this exists, just saying”. Since I got a chance to get the initial setup up, I could experiment and trial-and-error until I sorta figured out the rest of the system.

Since I seemed to seemingly be the only person on the planet to both have a passable understanding of this monstrosity and the willingness to write it down somewhere, I figured I could maybe spare other people from this madness. So here I am.

It would have been great to know about the sample project when starting. Epic should add a link to in on the GameplayAbility docs. The GameplayEffectsTests.cpp is old and not up to date code wise. That’s what i’ve been using up til this point.

Thanks for the writeup, the initial setup has been the biggest hurdle. You do however have a few typos:

  • You use AbilitySystemComponent at one point, AbilitySystem at others.
  • It’s not InitActorInfo, it’s InitAbilityActorInfo

That being said, I am extremely disappointed to see such strong coupling of the input to such an enum. Actually, I’m very disappointed to see it requires input binding at all. I want to activate my abilities manually through my own system, this feel like going against the grain of my entire infrastructure and design paradigm (that being record input in dedicated functions only, process it in Tick()). I’ll do some digging on my own to see how one would go about firing abilities manually without reliance on the BindAbilityActivationToInputComponent stuff.

Edit:

Ok so there are a few functions to manually activate abilities without binding them to input, namely:



	/** 
	 * Attempts to activate every gameplay ability that matches the given tag and DoesAbilitySatisfyTagRequirements().
	 * Returns true if anything attempts to activate. Can activate more than one ability and the ability may fail later.
	 * If bAllowRemoteActivation is true, it will remotely activate local/server abilities, if false it will only try to locally activate abilities.
	 */
	UFUNCTION(BlueprintCallable, Category = "Abilities")
	bool TryActivateAbilitiesByTag(const FGameplayTagContainer& GameplayTagContainer, bool bAllowRemoteActivation = true);

	/**
	 * Attempts to activate the ability that is passed in. This will check costs and requirements before doing so.
	 * Returns true if it thinks it activated, but it may return false positives due to failure later in activation.
	 * If bAllowRemoteActivation is true, it will remotely activate local/server abilities, if false it will only try to locally activate the ability
	 */
	UFUNCTION(BlueprintCallable, Category = "Abilities")
	bool TryActivateAbilityByClass(TSubclassOf<UGameplayAbility> InAbilityToActivate, bool bAllowRemoteActivation = true);

	/** 
	 * Attempts to activate the given ability, will check costs and requirements before doing so.
	 * Returns true if it thinks it activated, but it may return false positives due to failure later in activation.
	 * If bAllowRemoteActivation is true, it will remotely activate local/server abilities, if false it will only try to locally activate the ability
	 */
	bool TryActivateAbility(FGameplayAbilitySpecHandle AbilityToActivate, bool bAllowRemoteActivation = true);

Edit 2:

Sure enough, it works:

It did require a 1 frame delay, otherwise it wouldn’t work from BeginPlay through.

Needless to say, I do apologize for all typos in advance. AbilitySystem is not actually a typo however: The AbilitySystemComponent variable’s name is AbilitySystem, and it’s usually clear when I talk about the AbilitySystemComponent so I was being a little lazy on some ends. If it bothers people, I could just change all mentions to AbilitySystemComponent later on. I am however grateful for the input regarding InitAbilityActorInfo. I will fix this immediately

Input binding is recommended, but not 100% required, as you can just use the TryActivateAbility functions if you want to(I did mention them once during the setup, and I actually wanted to properly explain them in the next section), for example, trigger them by pressing an icon instead. However I am unsure how certain ability tasks that request the action mapping being pressed/released would react to this. I don’t think that’d work for example. You’d have to try yourself. I guess worst case you could just make do by using the Confirm/Cancel binds instead, which you should be able to fit into any game, frankly.

Other than that, the enum bindings have the same restrictions and strengths as any regular input binding; someone was probably just feeling fancy doing that enum nonsense.

It seems odd that you need the frame delay in BeginPlay though. I’m on the phone so I can’t check, but there is surely a better way to do this.

Well I wouldn’t trigger them in begin play anyhow. My issue is that my inputs are actually more like fighting-game inputs, so it’s not just a single input per ability. This makes the enum stuff completely unusable. What are these ability tasks that require action mappings that you refer to?

Also, sorry about the AbilitySystemComponent, I wasn’t clear - In your BeginPlay() function you do if(AbilitySystemComponent ) {… AbilitySystem.GrantAbility() … }.

No no, I don’t think the ability tasks I’m talking about would help you with this. They’re mostly for waiting for a confirm/cancel input, or waiting for the ability input to be released/ pressed again. What you could do is assign a unique ability to all inputs you want to use with a unique tag each and then just listen in an ability if the other ability is being pressed, perhaps cancelling that newly called ability in the process.

I do not know about the specifics of your fighting game-esque abilities. so it is hard to really suggest a proper solution of what you wanna do, but perhaps using gameplay effects that grant you new abilities the further you get into your combo could be a different approach? I am fairly sure that whatever you’re trying to do has a proper good solution, if perhaps a little roundabout.

Oh I already have an established system for reading my inputs. I also have a very detailed abilities and skill system that includes GameplayTags too. But all of that is reinventing the wheel - if GameplayAbilities are usable and working as intended, I was gonna consider switching to them, as I can afford doing that in this early project stage. I am not asking for any specific instructions, just analyzing the compatibility and general workings of the module.

Due to my input structure I need the module to be able to fire off an ability after my input is complete, which it seems it can do. As such I’ll have to research it a bit more… funny enough it seems to do something very similar to what I’ve been implementing and refining for the past ~2 years (namely that abilities are individual Blueprints that can spawn stuff like sounds and particle effects, have delayed effects after activation (fireball waiting for animation to finish). I just call them payloads though… the ability gets activated but its payload is delivered via an animation cue. In any case, my system doesn’t do any networking or replication since I didn’t require it. I’ll spend a few days digging through the GameplayAbilities to gauge if it’s overkill for me or if there are features worth switching for. The increased coupling with GameplayTags is interesting.

Hey KZJ i’m trying to make an effect that affects multiple actors at the same time and splits the damage between all the affected actors. Any tips?

I was thinking about adding a TargetCount to the attribute set and update that myself but i’m thinking that there is a better way to do it

I’m assuming you use a multiline trace within an ability to find your target actors, and apply the damage as modifier?

One possibility is to wait for me to explain GameplayEffectExecutionCalculations, which would make this a relatively simple endeavour as the execution can just check for the effect’s level(which is a float, and doesn’t seem to really be used for anything else except possible GameplayCue magnitudes so your own executions and such could freely use it) and multiply the damage of the effect accordingly(which wouldn’t just be useful for this ability either. All potentially scaling damage can benefit from such a setup). You would then do the multiline trace, divide your arbritrary total damage value by its length(aka the amount of actors you hit) and then applying a damage gameplay effect spec with the level totaldamage/HitResultLength.
You could do the same with just modifiers actually, as a 2 stack of a gameplayeffect will double the modifier’s effect, but you’d have to use stacks, which are only ints, so if your total damage cannot be smoothly divided by your amount of targets, then it’ll need to round.

If this is, say, a DoT effect that will dynamically split damage to bystanders each pulse/period, then that’d be a little more complicated. You could do this through a Granted GameplayAbility in the effect, or a GameplayEffectExecutionCalculation. The GameplayAbility would need something to trigger it in these pulses though, so you’d probably need a different GameplayEffect with a particular tag or just a GameplayEffectExecution as trigger, and the effect would perhaps be a little too specific to be implemented into a GameplayEffectExecution alone.

Hm, you’d probably need to give me some more specifics.

Thanks for the doc. You might post it into the Wiki later on, this should belongs to docs.

This system is just an amazing gift from Epic,but as you said, the understanding is “hard” but you can do a lot with it once you setup it properly.
I think you may not have mentionned enough, but from what I read, it’s multiplayer ready so the client input component will trigger the the ability and should run the stuff on server side. What I do not know as of today if there is something trigger immediatly on “client side” like FX or if it is triggered when the server said it’s ok… so with at least a ping delay.
I meant do you know if on client side there is a simulation on going that is “drive” by server answered. For example you call ability 1 that put a fx of fire, your client side cooldown is ok but not the serverside of it. what will happenned?

thanks for the good job on this!

I do not know the specifics of the replication other than the fact that “it just works”, and it’s kinda out of the scope of the guide(which is more about getting the initial setup, which is hard and more or less requires proper explanation from either someone or an example project, and elaborating on what systems the module has, how to use them and how they play off each other). The ability will first call itself clientside, expecting the server to soon call itself too. From the little testing I did with the net console commands, if the server calls itself with a certain delay(or perhaps at all delays, it just wouldn’t be noticable with slight delay), it will then roll back the events of the client side ability call and then make its own. This means Client Activation->Client Cooldown plays->Server Activation->Server syncs client cooldown with itself. If the client has enough delay to fire the ability twice, the server will execute it twice, too. Presumably, if the lag varies enough that the client activations fulfil the cooldown time but not the servers, the server activation will roll back the client activation, and finally sync the activation as if it had failed past the Commit Ability node(which checks cost, cooldown, etc.). The server likely does not roll back the client activation all at once, as there are ability tasks concerned with syncing client and server ability activation to a certain point.

A GameplayCue firing in that time(which would be the fire fx, most likely), though, will play only once during the client activation, because GameplayCues are set up in a way that they will neither be replicated, nor really “corrected” by the server(correcting a temporary visual effect would be very silly anyway, you’ve already seen it). That’s why it’s important for GameplayCues to really only be cosmetic effects. That being said, the gameplay cue will play for other clients and the server itself(when not dedicated) during the server activation. Ultimately, it works out in such a way that GameplayCues will only ever be seen/activated once per player.

I wouldn’t know about the wiki, or the fact that they allow user-made guides in that. Where do I find it and how do I post there?

For the wiki: A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

Thanks for the additional information. I bet the tool is rocking solid, they working with it since months not to say years, so I think we see most of the “edge cases”. I wish this was at this level 1.5 years ago when I started working on my game as I had to implement all of that… and not as good as they did :smiley: but it’s working for my game!

This is a really good documentation to start, with code samples, everyone will really appreciate!
There are a lot of small tasks to do to setup it that properly and it’s great that you describe them step by step!

So i’m working on a turn based rpg (think final fantasy mystic quest) that has abilities that can target all the enemies and when it goes to calculate the damage it divides by the target count (AttackPower * 4 - Defense * weakness / TargetCount). So i was trying to figure out the way to store and determine the target count. One issue is that abilities are triggered in queue so the target count will need to be updated when the ability is triggered but since the effect will be triggered for each enemy the target count would get updated while it runs killing the enemies modifying that count which i dont want (i could also not kill the enemies until the ability is done running which is also an idea). Using the game effect level is a good and simple solution since i wont be using the level for anything else. Thanks for that

Wow man thanks for your effort! do you know how “powerful” is that plugin i mean how limited it is?

Depends on what you want to do. Generally, you can do just about anything with this system because it is built to be extremely flexible and fit for radically different types of games and abilities(which makes sense, Paragon is a MOBA so having to add new stuff for a new hero’s mechanic would probably suck and Fortnite seems to be a tower defense with TF2-esque classes, so both these games would highly benefit from a system that leaves few limits), but there are certain genres and game types it’s better suited for than others due to the way, say, replication is handled, and if your game is simple and doesn’t require the scalability and such this system provides, it will very much be like killing a fly with an anti-aircraft missile, solving a simple problem with an amazingly inefficient and much more complicated solution.

I personally think I’ll skip it for now as my game is strictly single-player and I already have a pretty advanced skill system, which, having now moved it almost entirely to GameplayTags, is surprisingly similar in a few things it does. Still, gonna keep watch of this thread because sooner or later I’ll have to dig into this module.

Just a thought, do you think you shoul use it to manage Weapon also?
I mean “Fire” could be a ability. Is it worth it or standard replication with server RPC will be more efficient ?

To have a context, let’s talk about a hero shooter in FPS. You can fire and have some perks. What will be your approach with this? for the perks, the ability system fits perfectly but for th firing system that can interact with perks how would you do that.
Let’s say you have a perks that had DMG to your standard bullet firing.

The goal of this question is more to extend the usage of this module/tutorial and share idea of implementation ^^

Unsure if I understand the question fully, but auto-attacks/Weapons should probably use this system too when you’re already at using it anyway(so basically when the features the system provides don’t get in the way of your game), both because it is simple to do and because it provides consistency and can bind this aspect of your game into these systems as well.

Auto-attacks would likely be very simple gameplay abilities that will just fire a projectile and/or make a simple trace check in front of the character(when melee) after playing an attack animation, though that isn’t to say they can’t be more complicated and out-there. Perks would most likely be managed as permanent GameplayEffects/buffs, with things like damage, shooting speed, perhaps even shooting spread and the like being implemented as attributes in your attribute system of choice. GameplayEffectExecutionCalculations and GameplayEvents, which I planned on getting to today(tomorrow, at worst), can further trivialize the process because with ExecutionCalculations you can define a global damage calculation function for all gameplay effects to enjoy that can consider all stats and tags given into it as it sees fit. GameplayEvents can meanwhile be called by the damage calculation itself to give abilities the chance to add modifiers or do things in the middle of the damage calculation, and if you do plan to implement a global class for all weapon/auto-attack abilities, you may also set it up so that such a skill will always give an “auto-attack” Gameplay Event into the ability system for other abilities to react to(so you can do stuff like perks that go “every time the affected unit activates its auto-attack: Launch 2 extra projectiles in their general viewing direction”).

I do not mean to offend, but this tutorial is probably unfit for your first experience with Unreal c++, which from the sound of your problems seems to very much be the case. I would rather recommend one of Epic’s tutorials to ease you into the matter. I personally started with the battery collector tutorial, which was very helpful and leaves you with a fun little minigame that is simple in its rules and easy to expand upon. Anyway, uh, your points adressed from top to bottom:

  • Come on, while my introduction may or may not be poorly worded, I attached a picture specifically to show where to find this new Gameplay Ability Blueprint. It should be perfectly clear where to find it if you ever created a new blueprint class before.

  • If your Buld.cs file doesn’t build automatically when creating a C++ project, you have way bigger problems than being unable to follow this tutorial. I don’t know how you’d even be able to do this! Much rather, I believe you simply failed to open the folder containing the build.cs file within Visual Studio, as Build.cs will be found within the folder Source/MyProject.

  • Irrelevant. I couldn’t tell you why I have this module on and you do not, but we do not use it here and, as such, you are free to ignore this.

  • See previous point regarding Build.cs. The character files are in the very same folder as the Buld.cs file.

  • Quickly googling reveals that this error usually shows up when Visual Studio’s c++ compiler etc. are not present on your computer. Are you sure you installed Visual Studio’s c++ components correctly? An express installation will not do this: You have to go into custom and specifically tick the Visual C++ box.