UPROPERTY is null

Hi guys,

I’m trying to pass to a class that extends UButton a TSubclassOf UPROPERTY that points to a BP class. I then use this UPROPERTY to construct an instance through NewObject.

The problem I am having right now is that for some reason, at runtime the TSubclassOf is NULL and I don’t understand why. I guess it’s something really simple specific to UE4.

Could you have a look and let me know if you spot what I am doing wrong?


This is the (base) class of the classes that should be referenced by TSubclassOf.

// BBEvent.h

class UBBEvent;
class ABBHUD;

DECLARE_EVENT_OneParam(UBBEvent, FBBEvent, UBBEvent *)

UCLASS(Blueprintable, BlueprintType, DefaultToInstanced)

class SALTLAKECITY_API UBBEvent : public UObject
{
	GENERATED_BODY()

	...
};

This is the class that contains the UPROPERTY.

//BBButton.h

class UBBEvent;

UCLASS()

class SALTLAKECITY_API UBBButton : public UButton
{
	GENERATED_BODY()
	
	public:
		UBBButton(const FObjectInitializer & ObjectInitializer);

		virtual void PostInitProperties() override;
		
		...

	protected:
		UPROPERTY(Category = "Event Handler", BlueprintReadWrite, EditAnywhere, meta = (AllowPrivateAccess = "true"))
		TSubclassOf<UBBEvent> EventHandlerTemplate;

		UPROPERTY()
		UBBEvent * EventHandler;
};

This is how I try to use the UPROPERTY:

// BBButton.cpp

...

void UBBButton::PostInitProperties()
{
	Super::PostInitProperties();

	if (EventHandlerTemplate)
	{
		UE_LOG(LogTemp, Warning, TEXT("EventHandlerTemplate is not NULL"));
		EventHandler = NewObject<UBBEvent>(this, EventHandlerTemplate);
	}

	OnClicked.AddDynamic(this, &UBBButton::NotifyEventHandler);
}
...