Calling a function of a class from a TArray of classes

Hi.

I have a Skill class:

UCLASS(Blueprintable)
class THESIS_1_API USkill : public UObject
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintNativeEvent)
	static void OnPress(class ABaseCharacter* BaseCharacter, class ABasePlayerController* PlayerController);
	void OnPress_Implementation(class ABaseCharacter* BaseCharacter, class ABasePlayerController* PlayerController);
	UFUNCTION(BlueprintNativeEvent)
	static void OnRelease(class ABaseCharacter* BaseCharacter, class ABasePlayerController* PlayerController);
	void OnRelease_Implementation(class ABaseCharacter* BaseCharacter, class ABasePlayerController* PlayerController);
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TArray<TSubclassOf<ABaseCharacter>> UsedBy;
};

I’m planning to implement skills (abilities like a fireball for exemaple) as classes that would inherit the Skill class. I have an array of such classes in my BaseCharacter:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Skills)
TArray< TSubclassOf<USkill> > Skills;

And I’m trying to call functions from those skills classes in my BasePlayerController like this (CallSkill0OnPress is and action I’ve bound to a key earlier in the code):

void ABasePlayerController::CallSkill0OnPress()
{
	if (ABaseCharacter* BC = Cast<ABaseCharacter, APawn>(GetPawn()))
	{
		if (BC->Skills[0]!=nullptr)
		{
			BC->Skills[0]->OnPress(BC, this);
		}	
	}
}

And at this point I get a compiler error

Error C2039 ‘OnPress’: is not a member
of ‘UClass’

Which is strange to me as it looks like I tried to call OnPress from UClass, but up to this point I thought I only had USkill classes in the BC->Skills array.

What am I doing wrong here? :frowning:

Also: how do I add a class type variable (not an object of a class) to an array like the one I introduced in the BaseCharacter?

It is static, not a member.

TSubclassOf is same as UClass* it just limits class selection of classes in property editor to specific class relation. UClass is just representation of class in reflection system, you need to create object (or spawn if it’s actor) of a class in order to use it. So you need to do something like this on beginplay, i recomand to some renaming first:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Skills)
 TArray< TSubclassOf<USkill> > DefaultSkills;

 UPROPERTY(BlueprintReadWrite, Category = Skills)
 TArray< USkill* > Skills;

And in BeginPlay (or where ever you want skill to be initiated):

for(TSubclassOf<USkill> SkillClass : BC->DefaultSkills) {
     BC->Skills.Add(NewObject<USkill>(this,SkillClass))
}