Gameplay Ability System – Creating your own GameplayAbilityActorInfo

Published by on July 25, 2019
Categories: Unreal Engine 4

Here i will show you how you can use a custom GameplayAbilityActorInfo for your own project. This allows you to return more stuff for your specific project from your avatar actor/owning actor.

First step is to create a class derived from UAbilitySystemGlobals. So head into Unreal, create a new C++ class, and select AbilitySystemGlobals from all classes.

Next we need to override one function from there, called AllocAbilityActorInfo. So in your header do this under public scope:

then create the implementation inside your .cpp file, like so:

 

Next we need to create the actual struct for your custom GameplayAbilityActorInfo. For this its best to create a custom AbilitySystemTypes file. So head into unreal, create a new class of type Object and name it (ProjectName)AbilityTypes.

Now we will make some changes to this. Open (ProjectName)AbilityTypes header file and copy and paste this:

In the above we are going to return the ActiveWeapon the current avatar has. You can return/grab anything you like.

Now in your .cpp file, we will create this function to return the ActiveWeapon from the AvatarActor.

Don’t forget to include required headers in your cpp file, and to ensure you have forward declared pointer in your .h file!.

Next, we need to make the project load your custom AbilitySystemGlobal class.

Open up your projects Config/DefaultGame.ini file and add the following

replacing YourProject with your YourProject name and MyCustomAbilitySystemGlobals with your actual AbilitySystemGlobals class.

 

Now we have the custom struct initialized, and the engine using your custom AbilitySystemGlobals, we can now look at how to use it.

We will be using a c++ GameplayAbility for this, and just one function so you can understand how to use it.

 

As you can see above, we have to static cast to use our custom GameplayAbilityActorInfo. You can create a convienience function in your base GameplayAbility class for your project and
provide information from this custom GameplayAbilityActorInfo!

Any comments, suggestions, etc please contact me on my discord server

https://discord.gg/ksFJwE3

or using the comments box below!

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *