I’ve created a simple ActorComponent subclass with TSubclassOf UPROPERTY in c++. When I try to read this property in constructor it seems like it’s not set, even though I’ve set this in a blueprint.
That’s how things are set up:
.h:
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "ActiveSkills/BaseSkill.h"
#include "Includes.h"
#include "SkillSet.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class UNTITLEDGAME_API USkillSet : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
USkillSet();
// some other irrelevant methods her
protected:
UPROPERTY(EditAnywhere, Category = "Setup")
TSubclassOf<UBaseSkill> PrimarySkillClass;
};
.cpp (constructor only):
USkillSet::USkillSet()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = false;
if(PrimarySkillClass.Get())
{
UE_LOG(LogTemp, Warning, TEXT("Creating skill"));
}
else
{
UE_LOG(LogTemp, Error, TEXT("No skill class"));
}
}
In actor that uses this component I’ve set a class:
And even then PrimarySkillClass.Get() evaluates to false and I get “No skill class” in logs. What am I doing wrong?
I’m using UE 4.20.2