Characters in my game can execute 2 special abilities. A component ‘SPlayerAbilityComponent’ attaches to the character to enable this. I can then select their ability from blueprints since it’s a TSubclassOf:
SPlayerAbilityComponent.h:
UPROPERTY(EditAnywhere)
TSubclassOf<class USBaseAbility> AbilityOneClass;
UPROPERTY(EditAnywhere)
TSubclassOf<class USBaseAbility> AbilityTwoClass;
USBaseAbility* AbilityOne;
ASCharacter* OwnedCharacter;
The base class is USBaseAbility and the specific abilities inherit it. For example, USBoostAbility inherits USBaseAbility.
The SPlayerAbilityComponent.cpp creates a new object from the class variable and provides the USBoostAbility with the character when it’s used:
void USPlayerAbilityComponent::UseAbilityOne()
{
AbilityOne = NewObject<USBoostAbility>(this, USBoostAbility::StaticClass());
AbilityOne->Use(OwnedCharacter);
UE_LOG(LogTemp, Warning, TEXT("Ability one used."));
}
But I’m getting an error:
‘USBaseAbility::Use’: function does not take 1 arguments.
syntax error: identifier ‘ASCharacter’.
SBaseAbility.h has a Use function:
void Use(ASCharacter* OwnedCharacter);
and its implementation:
void USBaseAbility::Use(ASCharacter* OwnedCharacter)
{
// Execute the ability functionality.
if (!CanUse)
{
// Must wait for cooldown.
UE_LOG(LogTemp, Warning, TEXT("WAIT FOR COOLDOWN"));
return;
}
// Execute the ability and set a timer.
ExecuteAbility();
I’m providing it with a character argument but it seems to fail.
Any ideas why?
Thank you very much.