Download

PostInitializeComponents not working

Having some trouble recently with trying to have a bool show/hide a ‘UTextRenderComponent’. I have created a very basic TestActor and added this into the protected section:


virtual void PostInitializeComponents() override;

    UPROPERTY(EditDefaultsOnly)
        bool ShowMenuTitle;
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
        UTextRenderComponent* MenuTitle;

and then setup defaults/create components in the constructor


RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));

    ShowMenuTitle = true;
    MenuTitle = CreateDefaultSubobject<UTextRenderComponent>(TEXT("Menu Title"));
    MenuTitle->SetupAttachment(RootComponent);
    MenuTitle->WorldSize = 10.5f;
    MenuTitle->SetRelativeLocation(FVector(0.f, 102.f, 212.f));
    MenuTitle->SetTextRenderColor(FColor(60, 64, 67));

I then create a blueprint version of the TestActor, and can see the MenuTitle showing in the game. However, when I change the ‘ShowMenuTitle’ bool to false, and compile the blueprint, my PostInitializeComponents() is never hit:


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

    MenuTitle->SetVisibility(ShowMenuTitle);
}

I have another blueprint which is more involved and that does end up calling PostInitializeComponents(), but still doesn’t correctly hide my MenuTitle component. Am I doing something stupid here or using the wrong functions.