Setting property of a blueprint derived from custom C++ class

Hi all,

Apologies for what may appear to be a fairly obvious problem!

I have a custom “ability” type. The header appears like this:




UCLASS(Blueprintable)
class ROGUELIKE_API UAbility : public UObject
{
 GENERATED_UCLASS_BODY()

public:
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 UAbilityInfo* Info;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 AAbilityBehaviourActor* Behaviour;
};



The info object looks like this:





UCLASS(Blueprintable)
class ROGUELIKE_API UAbilityInfo : public UObject
{
 GENERATED_UCLASS_BODY()

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 FString Name;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 FString Description;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 TEnumAsByte<AbilityTypeEnum> AbilityType;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 float ResourceCost;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 float CastTime;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Abilities")
 float Cooldown;
};




Along with various other properties.

I had begun originally creating these abilities in C++ by instantiating these classes. What I want to achieve also, is the ability to create blueprints derived from these classes, and load them at runtime for use.

In aid of this, I have created a blueprint that has a parent of “UAbility”. I have also created a blueprint that is a child of UAbilityInfo, and contains all of the info for this new ability.

I would have rather have been able to set the info properties from the Ability object in blueprint, but that doesn’t matter for functionality purposes.

When I open the blueprint that derives from ability, I can see the Info property in the defaults pane. However, frustratingly, I cannot actually set that value to anything, including the AbilityInfo derived blueprint:

Where am I going wrong?

My hopeful end state is to be able to create these abilities by making a blueprint for each one, and setting the variables such as the Info before runtime.

Another, smaller matter is that the “ReceiveBeginPlay” event is never called on this custom UAbility blueprint. Is there somewhere to toggle that?

You can’t pick anything because your blueprint is a child of UAbilityInfo, but your code expect a native UAbilityInfo pointer.
Use TSubclassOf<UAbilityInfo> *Info; *instead then you can pick a class of a blueprint derived from the C++ class and instantiate it or get its default object to use.

UObjects can’t receive UWorld events, they have no builtin default implementation of a World instance, but you could implement yourself;
Else if you need blueprint events consider using UActorComponent instead of Ubjects.

Also, “Info” classes by design can be just a UStruct instead of UObject; this one is just a good practice to have tho.