The Actor Lifecycle

So I have been reading over the documentaiton on Actor lifecycles but I am having trouble trying to get my Actor to udate a Text render component in the ‘PostInitializeComponents’. I have setup a Test class, added a UTextRenderComponent and an FText:

virtual void PostInitializeComponents() override;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	UTextRenderComponent* InfoComp;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	FText InfoText;

In the constructor of my class, I create the UTextRenderComponent and attach it to the root. This all works fine and shows up in the editor, as does my variable.

InfoComp = CreateDefaultSubobject<UTextRenderComponent>(TEXT("Info Comp"));
InfoComp->SetupAttachment(RootComponent);

But when I try to set the text of the component to the variable I change in the editor in the ‘PostInitializeComponents’, it just doesn’t work? I have debugged to make sure it is being hit and all the variables are correct. Closing and re-opening the editor does show the changed text, however, I want the text to update as I change it in the editor, similar to if I simply changed the Text field or did it in the Construction script of the Blueprint.

/*virtual*/ void ATestClass::PostInitializeComponents() /*override*/
{
    Super::PostInitializeComponents();

    InfoComp->SetText(WrapTextFunction(InfoText));
}

I have changed ‘PostInitializeComponents’ to ‘OnConstruction’, however I just wanted to get some clarification that this would be the best approach?

PostInitializeComponents is called when the game is running. Before you hit Play or Simulate, the editor only calls the constructor.

If I compile my blueprint, it was hitting the PostInitializeComponents, just not doing anything with my components. I assume this was because they were overwritted in a previous function. I used ‘PostLoad’ in components and that works fine in the editor, just couldn’t find a good/correct option for an actor.

I thought you wanted to change the text of an actor in the world editor, not open the BP, change the text, and recompile.

Hello.

UObject::PostEditChangeProperty function is perfect to achieve such thing.

Example usage. Header:

#if WITH_EDITOR
	virtual void PostEditChangeProperty(struct FPropertyChangedEvent& InChangeEvent) override;
#endif // WITH_EDITOR

Cpp:

#if WITH_EDITOR
void ATestClass::PostEditChangeProperty(FPropertyChangedEvent& InChangeEvent)
{
	Super::PostEditChangeProperty(InChangeEvent);

	if( !InChangeEvent.Property ) return;

	const FName ChangedPropertyName = InChangeEvent.Property->GetFName();
	
	static const FName InfoTextPropertyName = GET_MEMBER_NAME_CHECKED(ATestClass, InfoText);
	if( ChangedPropertyName == InfoTextPropertyName )
	{
		InfoComp->SetText(WrapTextFunction(InfoText));
	}
}
#endif // WITH_EDITOR