Unreal Engine 5 Tutorials: Gameplay Ability System in 20 minutes - An Introduction

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Diablo Starfield cyber Punk Fallout there's one thing all these games have in common and that's abilities stats and status effects by the end of this video you'll be able to use the gameplay ability system to do exactly that so before we go down this rabbit hole and figure out how the ability system works I wanted to show you what we actually be producing by the end of this video we'll have two characters moving around both using melee attacks through their abilities both having a health attribute which can be modified by the attack stay tuned and I'll show you how to make the abilities and the effects and the attributes for all of this but before we start writing any code I want to go over some of these high Lev Concepts that the ability system has just so we are all on the same page and we understand what everything's doing firstly we have attributes these are basically a float under the hood which is just a number they are modified by gameplay effects to tie this to Something in Diablo the amount of Health the character has would be an attribute you then have attribute sets these can contain one or many attributes you can also then Define logic inside these attribute sets that manage how those attributes are modified going back to Diablo a character's attribute set might be made up of multiple individual attributes for example the health the movement speed the Mana next up we have gameplay tags these weren't really implemented for the gameplay ability system but the gameplay ability system makes heavy use of them an example of it would be status. negative. onfire they are really lightweight and they can be defined in both data and native code then we have gameplay cues they are usually pretty simple blueprints they are only for cosmetic use do not put any gameplay in these and they are referenced by gameplay tag this is how you will both add and remove them for example a gameplay que might be responsible for changing the Shader on a character when they're on fire next we have gameplay effects these are one of the heavy lifting classes within the ability system they're defined in blueprints they Define which attributes to modify along with whatever requirements they have they can set durations or they could be infinite or instant can also add or remove gameplay tags from an ability system along with any gameplay cues that we want to add whilst this effect is active it can also Define stacking rules for example example how many stacks of this effect we're allowed to have on any one target ability tasks think of them as Lego blocks that gameplay abilities make use of these are a specialized form of the gameplay tasks they are for asynchronous execution of code usually written in Native but you can do this in Blueprint too within the ability task you would define delegates these delegates would then help control execution flow within an a gameplay ability and they are explicitly tied to the life cycle of a gameplay ability so when the gameplay ability ends it cleans up after itself now we have gameplay abilities these are the bulk of what you're going to be working with in terms of the ability system they are primarily made in blueprints though you can do them in Native I would recommend not it will make use of all of those Lego blocks we defined earlier to then create an interaction that we want within the environment they can have requirements in order to run for example a specific gameplay tank has to be on a character before they're allowed to use it they can also have cooldowns so for example if I have recently used the ability I can tell it to a apply a gameplay effect and when that gameplay effect ends I'm allowed to reuse the ability so lastly we have the ability system component itself this is an actor component which can be applied to any actor in the scene this contains the abilities and the attributes it'll be used as a target for all interactions so that's a kind of high level overview of all the ability system components there's far more detail in the actual components themselves but I just wanted to give you a really quick overview of what each of these pieces do so when I mention them it's not completely out of the blue now in order to make use of the gameplay ability system in your project there's a few things you're going to need to do jump over to Unreal and open your plugins folder here you want to search for the gameplay abilities plugin and just tick the box next to it to enable it alternatively you can boot up your IDE find youru project and add the gameplay abilities plugin to your plugins section and set it to enabled we also want to go into the build. Cs for your project and even the public or private dependency modules make sure you add gameplay abilities so now we want to create our first attribute set in this case we're going to have a standard attribute set that all of our characters are going to make use of we Define an attribute by using the F gameplay attribute data struct we also want this to be a U property you may notice we have attribute accessors this is a combination of four macros that are built into the gameplay ability system this is to get the property itself defining a getter and Setter for the values and also initializing the property when it comes to a character attribut set I tend to define a health a health max and a damage this damage is going to be a meta attribute all of our gameplay effects will apply damage to the character and then that will be removed from the health we will then add some logic to stop the health from going below zero and also going above health max so we want to override the Dage via the damage attribute instead of modifying the health attribute directly we can change what that calculation does in the future so let's go into what the post gameplay effect execute does this is called every time a gameplay effect is applied to the ability system which controls this attribute set as you can see here we check to see if the damage attribute is the one that's being evaluated if it is then we store the damage value because it's already been set we then reset it back to zero because we don't want to keep that persisting so if the amount of damage done is greater than zero we now want to modify the health and set it that way we have damage applied via the damage attribute and if we wanted to extend this in the future we could change the calculation here now as I mentioned the damage attribute is servide only this means that we're not replicating it at all the health and health max are replicated and they are replicated using their own functions we've defined them here so let's just go into them very quickly we use this macro gameplay attribute rep Notifier this tells the underlying ability system which contains this attribute set that the attribute has been modified without this function the ability system would be unaware of any replicated value changes so it's very important that we have this so now that we've created an attribute set we can actually start creating gameplay effects that can modify those attribute sets we've created here a blueprint class by just right click blueprint Class Type in gameplay effect and then press the gameplay effect select the naming convention for gameplay effects is GE so geore demo in this case so you see on the right side here we have duration policy this could be instant infinite or has duration if you set it to has duration duration magnitude will be visible you'll be able to set a value here which will Define how long the gameplay effect is active for next up we have modifiers these are attributes that the gameplay effect modifies created a first array element we'll notice it says attribute here we need to choose the attribute that we want in this case if we're making a damage effect we would set it to the standard attribute set. damage and the magnifier op to add there are multiple magnifier Ops for example if you wanted to half the amount of Health a character has you could go to health divide and type point five but in this case let's just do a simple damage we're going to just simply add five damage to the character now each of these modifiers you can require both the source and the target to have certain tags for example if you wanted to make it so you could not apply damage to a character if they have an invulnerable tag you would go to the Target tags ignore tags and then set the specific tag you would like so both the source and Target tags have require and ignore if a tag is required then the Target or the source will have to have that gameplay tag applied to them if an inor tag is set then an ability system must not have any of the tags defined gameplay effect executions are slightly out of scope for this tutorial they are a somewhat more advanced feature of gameplay effects but I will cover them in a future video conditional gameplay effects allow you to add additional effects if the current effect applies to a Target so for example if this effect applies correctly to a character I may want to also make it do a slow effect so I would add a slow here if you have a duration policy set to has duration you'll notice that there is a period value here this is similar to a DOT effect if the period is set to one then every single modifier will be fired every 1 second under the tag section you may see that there's a bunch of different options here I'll go for each one okay so to start with the gameplay effect asset tag you can apply a single tag to this gameplay effect itself this makes it easier for querying later the granted tags allow you to add individual gameplay tags to a Target as long as this gameplay effect is active on a Target they will have the gameplay tags defined here you can also set tags for abilities that you wish to block if the gameplay effect has a duration you may want to use the ongoing TAG requirement an ongoing TAG requirement is something that will be used to determine if a gameplay effect is on or off um treat it like a suppression if I have a gameplay effect that Buffs my character in some way but I want it to be suppressed if they have a stun applied to them they can have an ignore tag set for status. stun for example and if I have that tag this effect will not be applied but the moment that tag is removed the gameplay effect will come back application tag requirements are tags that must be set on the ability system which has this effect applied to it for example if I wanted to apply a buff to a character if I required the target to be alive for a buff to work I could set the required tags to status do alive and then the character would have to have that tag in order for it to apply the inverse is true with ignore tags so the tag cannot be present so removal tag requirements function similar to how the application tag requirements do but if that tag is ever applied to a Target it will remove the gameplay effect immediately lastly we have remove gameplay effect query and remove gameplay effects with tags these function very similar to one another I'll just go over the tags one for now if for example you wanted to remove another gameplay effect from a character you could specify the tag here it will check the gameplay effect asset tags on all of the gameplay effects applied to a Target if any of them match it will remove that effect next we have the granted application immunity tags so for example if you wanted to make yourself immune to crowd control you could set the tag here to status. crowd control and any tag with the gameplay effect asset tag of crowd control would automatically fail to be applied because you have immunity to it next we have the stacking type by default this is set to none which means that every single instance of a game playay effect is treated as an individual instance of it if you said it to aggravate by Source or aggate by Target it will count them together as a single instance and you can put limits on how high that stack can go the stacking type can be set to aggregate by Source or by Target if I wanted to make sure that my own character could only ever be affected by five instances of a specific type of gameplay effect I could aggregate by Target if I wanted it to have the cter can only have five active at any one time it would aggregate by Source there is a duration refresh policy which can be set to various things same with the period reset and the stack expiration policy you can also set a stack limit by default this is zero but you can set it to any number you wish and lastly we have granted abilities these are abilities that are granted whilst this effect is active and they will be removed when this effect is removed you'll notice the gameplay effects themselves have no blueprint functions they are purely data assets so for a real world example of a gameplay effect we have geore initial character stats this has an instant application so its duration is instant it sets the health max and the health attribute to 100 by setting the modifier op to add and setting the magnitude calculation type to scalable float and the scalable float to 100 so now we've created our attribute set we want our character to make use of it we also want to give it an ability system component so it knows how to interact with the world so to do this we're going to create two properties on the character itself they are both U properties one of them is going to be the ability system component itself and the other is going to be a standard attribute set the thing we just created so in order for Ability systems to interact with one another they need to have a common interface this is called the ability system interface we just want to implement this quite a simple function all we have to do here is just return the ability system component property that we just created now in the characters Constructor we want to create two subobjects one is the ability system component one is the attribute set because these are both actor components under the hood they will just attach directly to the character now the next thing we want to do is on begin play we want to set up its initial abilities and effects so the initial effects will be things that set the initial Health state of the character so in this case I'm going to set the health to 100 and the max Health to 100 so I've created this function here set up initial abilities and effects within this function I use an initial ual gameplay effect I've just created a subass of a U gameplay effect and made it a property on the character Now using the ability system component I can now apply that effect directly to itself now we also want to add abilities to the character to do this I've created this initial ability set now I've also made this U ability set class this is quite a simple class but it's very powerful it allows us to define a group of abilities with their input bindings it's just a u data asset which means that we can Define everything in data it's just an array of game play abilities so we just store the class of the gameplay ability we want to use we then also take in the input key that we want it to be bound to in this case I've made an enum jump primary secondary attack the ability set class also has a function called Grant abilities to Ability system within this function we pass in the ability system component that we created earlier we then go over all the abilities that we defined in this data asset we then give those abilities directly to that ability system whilst also binding the input ID that we've defined the input ID is just an integer in our case we've defined in an enum but you could just hardcode this to whatever numbers you want I would recommend using an enum for ease of use later down the line as you can see in this setup initial abilities and effects function we're just telling it to Grant the abilities via that function we just created allows us to completely Data Drive our initial abilities and the effects and lastly we have our input bindings this is just a bridge between the enhanced input system and the gameplay ability input this is done by a simple array we just pass in the input actions and then we also pass in the enum variable that we want and then on the actual setting up of the player input component we're setting the triggered and the complete events we're then passing in the input ID the Handler is then going to fire ability local input press to the ability input that we've just passed in it sounds like a lot but in the input bindings for your character whenever we press the key Bound for this it will activate the ability bound to this for the initial character abilities you can see how we've bound the jump ability to the jump key the melee attack ability to the primary attack and the melee block to the secondary attack okay so now let's create an ability in this case we have gaore melee attack this was created by right clicking going to gameplay gameplay ability blueprint and then deriving from gameplay ability this ability itself has no ability tags it doesn't cancel anything it doesn't block anything it doesn't have any owned or any other tags I'll go through that in a second but this is quite a simple ability it plays a montage and waits for it to finish and when it finishes it ends the ability whilst this montage is playing it also waits for a gameplay event called event. m. attack it will only trigger once and then when that event is received it will collect the target data by using this weight Target data node there are various targeting systems that you can use with the gameplay ability system in this case I just chose a really simple one which is just doing a radius check so the way this targeting system works it grabs everything around a location within a certain radius uh we are just grabbing the character's location setting it for forward slightly passing that into the targeting data and because its confirmation type is set to instant it will instantly return and then jump into this valid data or cancelled if it has valid data what it will do is get all of the actors from the target data that's returned iterate over them try and get their ability system component under the hood this is calling that interface that we defined earlier it checks to see that it's not applying damage to itself F that passes it makes an outgoing gameplay effect spec based off of a standard damage class which we've defined here the way the standard damage works it just has an instant duration policy it just sets the standard attribute sets damage variable to whatever is set by the caller magnitude calculation type is set by caller and the data tag is a set by caller. damage amount by making an outgoing gameplay effect spec we can now assign that call of magnitude in this case we're setting it to 10 and then finally we call apply gameplay effect spec the target this is a function on the ability system component we're using the owner's ability system component to Target the target's ability system component and then applying that spec to it I mentioned in the past we have these ability tasks they're kind of like Lego blocks you can see how quickly you can put them together to get designers building functionality within a game very quickly and because they're all Native code under the hood they're relatively fast now that's not to say you can't make really inefficient blueprints with gameplay abilities but they should all roughly be around this size very rarely do you want to have a humongous long lived gameplay ability now I previously mentioned you have these properties that that come with the gameplay abilities themselves so ability tags cancelling abilities Etc let's just quickly go over each one of these so ability tags are similar to the gameplay effect asset tags these are tags that are applied directly to this gameplay ability it makes it easy in the future for searching for things for example cancelling abilities with tags we'll check to see if you have any abilities that match that tag moving on we have cancelling abilities with tag and blocking abilities of tags what cancel abilities with tags does it checks to see if you have any abilities that are currently active and if they are do they have any ability tags that match if they do they are canceled immediately Block abilities of tags is similar it checks to see if the ability has any tags when they're activated and if they match they are blocked from running activation own tags adds gameplay tags to the ability system that's controlling this ability so once this ability is activated it will grant certain tags activation required tags they simply are tags that are required on the ability system in order for this ability to function if it doesn't exist it won't run activation block tags is the inverse of that activation block tags requires that the ability system does not have a certain tag listed here next we have replication policies this is for multiplayer uh if you are going to be making multiplayer games some abilities you may want to have replicated we will talk about Network replication in the future and we'll go over how this works with gameplay abilities next up is instancing policy there are multiple policies I tend to use instance per actor this means that there's one single ability per character that's using it uh instance per execution creates an individual ability per instance of that being activated I don't recommend that because it's quite because you end up having quite a few I've never use non- instance but I can see cases where you may want to use that next you have server respects remote ability cancellation again this is for replication if you cancel the ability locally the server should also cancel the ability and then you have re-trigger instance ability then you have net execution policy uh by default this is locally predicted sometimes you may want to have this the server only or local only we'll go into this in detail in a future video with network prediction and replication on gameplay abilities there's also a network security policy again we'll go over that in the future this cost gameplay effect class think of this like Mana in Diablo you can apply a gameplay effect as a cost of using this ability uh the same with cooldowns so cooldown gameplay effect class this is a cooldown that you can add which is normally a specific gameplay effect that has a duration of some kind and a tag it checks to see if that tag is still on the character and if it has that tag it's unable to use the Ability anymore until that tag expires and then you also have ability triggers there are multiple ways to activate an ability the one we are using so far is just triggering via input so whenever we press a key like in this example left Mouse button whenever we press that it will activate the ability for example if I had a tag added to my ability system and I had an ability that was waiting for that tag to be added I could have it activate immediately upon that tag being given to me I could also have it triggered based off of a gameplay event uh gameplay events are basically just gameplay tags that have additional data associated with them um as you can see here we're using it for the melee attack uh the melee attack itself in the animation Montage I've defined an animation Notifier so you see this position here this is an animation notify in the blueprint for this I just get the owner and then I pass the gameplay event that I want it to fire in this case I've set the gameplay event tag to event. m. attack which means that the moment that this point in the Montage is reached it sends that event that event is then picked up by this node here lastly we have Source required tags and Source blocked Target required tags and Target blocked these are only ever used when triggered via gameplay events so if you set a trigger source of gameplay event and pass in optional targets or optional sources it will check the tags on those assets here now you'll see if I hit the left click the ability is playing on both characters even though it's networked and the health is also modified if I left click so that's the gameplay ability system set up and running so this is a very high Lev look at what the gameplay ability system can do there's a lot more detail in the future that I want to go over but for now I want to leave it here so if this video has been helpful for you if you could both like And subscribe it would be really helpful for me to grow the channel anyway thank you very much and I hope this has helped take care see you later
Info
Channel: Dan Goodayle
Views: 13,245
Rating: undefined out of 5
Keywords: Unreal, gameplay ability system ue5, game development, epic games, unreal engine 5, unreal engine, unreal tutorial, ue5 tutorial, ue5 guide, unreal guide, ue5
Id: s3-kOmP5bVw
Channel Id: undefined
Length: 21min 28sec (1288 seconds)
Published: Mon Oct 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.