[Help] Add Abilities at Runtime - Lyra Project

Hello,
I’m currently working on adding a system to the Lyra Starter Project that allows a player to choose a unique ability for their character before a match begins. (Think Load-Outs)
I’ve created a handful of abilities from a base class using GAS and now am trying to implement choosing an ability at runtime.

It’s pretty easy to add an ability to the AbilitySet defined for an experience, but this approach doesn’t allow me to change the ability at runtime. I’ve set up input actions to trigger the ability and verified they work by adding the ability like this:

However, if I add the ability to the character at runtime using the “GiveAbility” function, I am unable to activate the ability. The “Event ActivateAbility” does not fire inside the gameplay ability class. Here is how I’m adding the ability to the B_Hero_ShooterMannequin:

image

Here is the ability trigger set up inside my gameplay ability:

image

If someone could offer some advice on this topic it would be much appreciated!

1 Like

Just providing an update to my previous question… I found a solution that has allowed me to choose an ability to activate at runtime!

First thing I did was added all my abilities to my Hero Ability Set. (I plan on separating primary ability references out into their own ability set for modularity)

In the base class I added logic to resolve the active primary ability.

Lastly, I add a call to this method when activating the ability.

I use an actor component to set the active primary ability on my player character.

Hopefully this post helps someone else working on their project!

2 Likes

Good to see you figured that out. Is that “player ability component” a default component or is a custom one created by you?

I was thinking about this topic after a conversation with another user a few days ago. I also would add all abilities in the ability set as you did, then, based on selected character classes in the main menu, I would remove everything not listed in the selected class array, if that makes sense. I give it a try in the upcoming days and update here if I find anything.

I created a custom player ability component. It provides a way for me to set the correct ability at runtime. I plan on having the player be able to change their ability mid-game, so I will still need a reference to all ‘primary abilities’.

1 Like

My understanding of your setup: Player ability component stores the list of abilities granted to that player (from a selected load-out or character class). Then, the ability will be activated only if it is assigned to the player’s load-out (can activate ability check). To me, it seems to be a good workflow. Well done.

I quick tested calling the Add Ability node from event possess with GA_AutoRespawn and GA_Emote. First, I removed both abilities from the ability sets, then, after event possess in Hero Shooter, I added an AI Bot check, and connected two Add Ability nodes with Auto-Respawn and Emote abilities. I found that this method only works with GA_AutoRespawn, which is a passive ability. GA_Emote didn’t work and the most likely reason is that this is an active ability associated with input tags. Therefore, something else is needed to allow adding active abilities at runtime, or the new Lyra’s setup won’t allow it without C++ custom classes.

I am avoiding modifications on C++ classes as much as I can, and I’ll update here if I find a blueprint-based solution.

I’ve tested again that setup, removed GA_Emote and GA_Grenade from the correspondent ability sets, and added a function after event possess inside Hero Shooter Mannequin.

For an array of ability classes selected from the main menu, connect a “for each loop” and Give Ability. The output needs to be added to an array of GA Spec Handles. Then, for each array element, set an input action or re-use any existing ones calling Try Activate Ability. The nodes inside green boxes work correctly, and none of the tags can be used as triggers for the abilities granted in runtime. Unless there is something else missing.

This is the solution that worked for me. I still get the benefit of using tags for activation and other tasks.

I created an Ability Set granting all possible gameplay abilities. Each ability inherits from a base class. The all are triggered by InputTag.Ability.Primary. You would have to follow this same procedure for each input tag you wanted to dynamically map abilities to.

I then added that Ability Set inside HeroData_ShooterGame

Inside B_Hero_ShooterMannequin, I set the primary ability class using a custom component. I can use this same method to set the primary ability inside a UI.

From here I just check that the activated ability matches the primary ability set via component.

This clears up a lot of additional logic in the Hero class and leaves it all up to configuration. Hopefully this clears things up a bit.

1 Like

Thank you for sharing your solution. I believe that is the best way to do it. Well done.
I was wondering that another way to do it without coding a custom class would be adding all abilities in the ability set, then assign tags to the player “classes” and use those tags as activation requirement tag inside each one of those GAs.

Conversely, considering my tested setup, I’ve lost the possibility of using tags for remote activation. I’ll see if I can dive deeper on this topic in the upcoming weeks.

Keep up the good work.

1 Like

Hi, your solution made me think in a different direction towards minimum C++ modification. Guided by your example, I granted all abilities in the ability set. Then, I created a simple blueprint interface that gets an array of granted abilities classes updated after the event possess (based on selected class in the main menu). Then, I modified the function Can Activate Ability that checks if that particular ability is contained in the Ability Loadout Array. That’s it. Problem solved. And I am still benefiting from all input tags and tags relationships necessary for remote activation. Thank you.

Similar results would also work with gameplay tags granted by childs of GE_DynamicTag.

4 Likes