Download

Add custom AActor to object

I created AActor that has text render component that rotates toward player (I have the rotating text tested and working).

This is the header file:



UCLASS()
class SURVIVALGAME_API ASPlayerFacingText : public AActor
{
	GENERATED_BODY()
	
public:	

	// Sets default values for this actor's properties
	ASPlayerFacingText(const FObjectInitializer& ObjectInitializer);

	void SetText(FString NewText);

	virtual void Tick(float DeltaTime) override;
	
	UPROPERTY(EditDefaultsOnly, Category = "Text")
	float TextWorldSize;

	UPROPERTY(EditDefaultsOnly, Category = "Text")
	FColor TextColor;

	UPROPERTY(EditDefaultsOnly, Category = "Text")
	FString Text;

private:

	UTextRenderComponent* PlayerNameText;

	void RotateTowardPlayer();
};


No I wanted to add this to my player pawn in c++ class so I added property in header:



public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player")
	ASPlayerFacingText* PlayerNameText;


and in constructor I added these lines:



PlayerNameText = ObjectInitializer.CreateDefaultSubobject<ASPlayerFacingText>(this, TEXT("PlayerNameText"));
PlayerNameText->SetText(TEXT("TODO: NAME"));


I can see the property but I cannot see the text in preview with it default values … am I missing something?