I have a custom APlayerCharacter
actor class with UEquipmentComponent
that should hold UEquipmentSlot
s references.
UCLASS()
class ACTIONCOMBAT_API APlayerCharacter : public ACharacter
{
GENERATED_BODY()
public:
APlayerCharacter();
protected:
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
UEquipmentComponent* EquipmentComponent;
};
UCLASS()
class ACTIONCOMBAT_API UEquipmentComponent : public UActorComponent
{
GENERATED_BODY()
public:
UEquipmentComponent();
public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Equipment")
UEquipmentSlot* WeaponSlot;
};
UCLASS(BlueprintType)
class ACTIONCOMBAT_API UEquipmentSlot : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TSubclassOf<AEquippableItem> ItemClass;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
AEquippableItem* Item;
};
These slots are defined as a series of fields that are initialized with default values in compnent’s constructor.
UEquipmentComponent::UEquipmentComponent()
{
PrimaryComponentTick.bCanEverTick = true;
WeaponSlot = CreateDefaultSubobject<UEquipmentSlot>("Weapon Slot");
WeaponSlot->ItemClass = TSubclassOf<AWeapon>();
}
The thing is that blueprint deriving APlayerCharacter
only have this default value for the slot for a single session after reparenting it to APlayerCharacter
. After restarting the editor or after playing single simulation session it is set to None in the blueprint. I can reparent it again to have this reference set to an instance of UEquipmentSlot
for a single session.
I want it to be initialized in the constructor with the value. Slots are never to be replaced (only Item
s inside them). They should be constant for EquipmentComponent and initialized with default value that is preserved between sessions.