I found that the execution logic of some skills was exposed in the blueprint,How can I implement this skill code and pass it to gameplay ability variable in C++ , Should I override activateability() in gameplayAbility.h?
I’m sorry for my poor English. I used google translate.
Hi, not sure if you need just one variable or the entire logic to be in C++. Yes indeed you can extend the UGameplayAbility class with your own custom class that executes your ability. If necessary, yes you can override ActivateAbility() as well. Your class can have any other variables that you need that can be set in blueprint etc., just like in other situations. Remember to commit your ability, whether in code or blueprint (I don’t see a CommitAbility node in your picture!)
Thank you for your answer.
In fact, I just want to put the implementation of skills into my extended MygameplayAbility.cpp.
But I don’t know how to add my code after the Node[Event ActivateAbility] as in the blueprint.
Hmmmm not sure I follow what you mean. If you want to call your c++ code as a node from within the Ability blueprint (GA_ blueprint basically), then define your function(s) as BlueprintCallable in your child UGameAbility class and you should be able to call them from your GA blueprint.
Thank you. This problem has been solved. But I encountered a new problem. When I call gascomponent - > giveability() in beginplay() and pass in the custom ability class, it will crash when the game is running.[alt text][1]
It would have been helpful to see the crash error log, but I think your code also is a bit problematic. You don’t need to create a new object for the ability in order to ‘give it’ to the character. The component does that for you behind the scenes. You need to pass it a class reference (I think you’re trying to pass an instantiated object in that SpecHandle, which I haven’t seen it work like that).
Create an FGameplayAbilitySpecHandle and pass it to GiveAbility like so:
const FGameplayAbilitySpec AbilitySpec([class type of your Ability], 1[this is Level input and 1 is fine, [some integer value for input code (make them unique for each ability if you can)]);
BQAbilitySystemComponent->GiveAbility(AbilitySpec);
I tried your suggestion. Maybe I didn’t correctly understand the meaning of [class type of your ability], but my code couldn’t be compiled. Attached is a screenshot. I hope you can point out my error