Download

FString passed by reference to delegate function called by SetTimer() not udpating

I have an FString that I am passing by reference to a function on a timer set to loop. Each time the function is called I want the string to be further modified; however the original string being passed seems to be treated as if it’s being passed by value.

For example, I would expect the code to below to add successive periods to the end of moddedText. Instead, each type Type() is called, the original version of moddedText is passed to Type and the result is always that only a single period is added - as if moddedText was being passed by value.



void URichTextBlockExtension::StartTyping(const FText& InText, float DisplaySpeed) {
      FString moddedText = InText.ToString();

     TimerDelegate.BindUFunction(this, FName("Type"), moddedText);
     GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, DisplaySpeed, true);
}

void URichTextBlockExtension::Type(FString& moddedText) {
      moddedText = moddedText.Append(".");
}


The problem seems to be stemming from the call of Type() as a delegate function passed to SetTimer(). Direct calls to type pass by reference as expected. How can I fix this?