How can I have a UTextRenderComponent change/update itself properly in a networked environment using an INT?
I have an INT variable similar to a Score like variable that I’d like to have displayed on the wall whenever the INT changes. I am stuck with the implementation and also the proper syntax to work with the textrender as I am not sure if the conversion from an INT to text is right.
Here is what I have.
.h
UPROPERTY(Replicated)
int32 CountUp;
PROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Counter)
TSubobjectPtr<UTextRenderComponent> Counter;
void DisplayText();
.cpp
(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
Counter = PCIP.CreateDefaultSubobject<UTextRenderComponent>(this, TEXT("Counter"));
if (Counter!= NULL)
{
Counter->Text = TEXT("XX");
}
}
void ACheckDart::OnRep_Countup()
{
DisplayText();
}
void ACheckDart::DisplayText_Implementation()
{
Counter->Text = FString::Printf(TEXT("%i"), int32(CountUp));
}
void ACheckDart::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION(ACheckDart, CountUp, COND_InitialOnly);
}