Transcript for:
Gameplay Ability System in Unreal Engine

alrighty the game play ability system we've got plenty of things to get into today to get started with so let's get into it first and foremost we're going to go up here into plugins of course and we're going to look for gameplay abilities you want to turn that on you also want to check whether or not you have gameplay tags enabled it should be enabled by default but if for some reason you don't have it enabled do make sure you also have this one because the gameplay ability system makes use of gameplay tags a lot anyway we want to restart the unreal editor and then we can actually get into it okay so a few things before we get started we are going to need to use a little bit of C++ to set certain things up which can only be done in C++ just the setup will be done there and a few of the more complicated calculations that we'll need to do eventually also are limited to C++ for the most part this entire system is made to be used in blueprint and to make it easier for gameplay programmers don't really know how to use C++ too much to quickly and efficiently make gameplay abilities for a game that needs a lot of them if you just need a game with like a handful of attacks it might be better to manually program that yourself but it's still good to dive into how this works and just explore the option that's that if you have a project that has been made and set to be blueprint only what we can do up here is we can uh still come up into tools and make a new C++ class that will then generate all of the code for you and start using C++ in your project if you're entirely new to C++ please do go check out my C++ Basics course you don't need to follow it all the way through but the first like four or five videos just to know more or less what is going on on the C++ level here you will really kind of need that then when we have the C++ enabled for our project project we can open in Visual Studio or Visual Studio code or whatever you might be using and we have our IDE ready coming down into source and then in your directory for your project itself there should be a couple of ones in here already like the third person character if you used the third person character template I'm assuming that you did and then some other things as well the most important thing here being uh your project. built. CS this is one of the very few C sharp scripts that you're going to have uh using Unreal because usually everything is C++ this isn't C and what we need here is we have a public dependency modules. add range and this is just adding separate modules that we may or may not be using to allow the engine to access that kind of code these are all the public modules but you can also add private the dependency module names this is using GitHub co-pilot this is entirely right we should be adding the gameplay abilities the gameplay tags and the gameplay task when you've added these to the private dependency modules you can also add them to the public ones that will still just function that is how I have it set up in my own project uh but you should add them to the private modules you want to either uh use live coding or just rebuild your project and open it up again we're going to use live coding here because that is fine and that will then allow you to actually start using the gameplay ability system so let's get back into the engine here because it's easier to navigate to different classes uh that we're using here and what we're going to do is we're going to get our um guas tutorial Basics character and let's open that up which opens up the H file for that character now we need to add the gameplay ability component through C++ because we're going to need to uh interact with it through C++ a little bit and things added and blueprint are more or less invisible to C++ in here let's go into the protected section and I'm also going to remove the uh look and move functions that we have in here because I have those set up on my player controller that I made off screen as well as jumping and the entire uh player input will be uh delt through the controller this is just basic project setup this is not specifically to do with gameplay abilities but I just want to clean up a little bit of this C++ stuff so we only have all of this left now in our protected section we're going to add a U property and that U property uh will be uh for now at least of type added anywhere we want blueprint read only so not read right we want read only we don't want to be able to write to this and the category will put as gas for gameplay ability system and then for meta allow private access uh we're going to set it through as well and of course that is going to be uh something of type class U ability system component pointer and we'll call that the ability system component that works out fine for me and then we'll come over into the CPP file into the Constructor of this class and we'll just go to the very bottom here and we'll say our ability system components equals create default sub object of Type U ability system component and the name of it is going to be the ability system components in order for this to work though we need to come up here into the includes and we need to include the ability system component. H now let's head back to our header file here because we're actually going to need to use an include in here too which is quite unusual usually you try to avoid including things in your header file but in this case we want to include a interface that being the ability system interface. h this is going to allow us to get an easy function to get the ability system components on this character from anywhere and everywhere very easily and you can overwrite this kind of stuff you can do whatever you want with it you can if you understand interfaces you know what you can do with this if you don't understand interfaces just go along with this maybe watch my blueprint interface video specifically on that it's very very good stuff because with that header file included we can now also after uh our public a character put a comma and then we can include the interface so that will be our public I ability system interface which now we have access to the functions that live on that so the one that we're going to be using will be the virtual U ability system component pointer get ability system component which will be a const overwrite and that will just simply return our ability system component now you can overwrite this on different classes to do different things and return different ability systems so for instance if you have a class that for some reason is like a minion of a bigger enemy and it doesn't have an ability system component of its own because it just refers to the ability system of its owner like the boss fight or something you can then override the function on that specific class to not return its own ability system component but look at its parent and return that ability system component so you can change the actual implementation of this on a caseby Case basis if you need to which is the whole point of an interface if you keep getting these uh errors like I am what you want to do is you want to uh reveal this file in Explorer and we can simply just generate Visual Studio project files and it will regenerate some files when you make new classes sometimes Visual Studio at least vs code gets a little bit confused and with that we have now added everything in here for for our ability system component so if you want to add an ability system component to your enemy actors which we'll do in a moment as well you pretty much do these steps to add it to those things as well uh I also want to point out that I misspelled virtual and I didn't forward cleare the U ability system component which was kind of an issue that all fixed now we can compile and we should be able to see in the engine itself we have our ability system components on our character now and our default third person character that we have here now has a ability system component which we can get into all of the more detailed stuff about how we use that and how we actually do the stuff with gameplay abilities that we want to do a little bit later but for now suffice it to say we have our ability system component and we can use this get ability system component function and this can just be used on any actop so if for instance I am in My Level blueprint and I want to get player character which will return a generic character reference I can still use the get ability system component on that and it will run the function that we've just overwritten in C++ and return us the ability system component on that character so that is the reason we needed to set all of that up because I have a couple of characters here that I downloaded from the unreal Marketplace from the Paragon selection and these ones inherit from the normal character class so we're actually going to change that to be based on the gas tutorial Basics character instead and now you will see these ones also now have ability system components and trying to replace a couple of the components with other components but that doesn't matter so we got that and I'll also go into the thing that we're eventually going to turn into the enemy that we'll be fighting which all of this stuff is deprecated code which doesn't work anymore so we're going to just remove that and then in our class settings once again will'll base this one on the tutorial Basics character so that it gets an ability component and for now that means that we have our setup with our enemy which is going to use that in its Behavior tree eventually and our main character which now has access to abilities system components but there's one little issue there and that is said it doesn't do anything yet and that's what we'll get into next time next time we're going to get ourselves a HP and something like a stamina or a MP magic stat whatever you want to call it and a very big thank you to all of my patreons you can see them on screen right now if you want to help out supporting the channel there's a link Down Below in the description to the patreon page and a special thanks to my C dle tier patreons Serge Thomas