Download

Slate: bind doesn't seem to be updating floats, but updates FStrings

Hi all,

I have


TAttribute<FText> WorldSeason;
FText GetWorldSeason() const;

TAttribute<float> WorldTimeOfYear;
float GetWorldTimeOfYear() const;

in my slate widget’s header and


FText SStandardSlateWidget::GetWorldSeason() const
{
	UonwardGameInstance* GI = Cast<UonwardGameInstance>(OwnerHUD->GetGameInstance());
	if (GI) { return FText::FromString(GI->GetWorldTime()->GetSeason()); }
	return FText::FromString("- no season -");
}


float SStandardSlateWidget::GetWorldTimeOfYear() const
{
	UonwardGameInstance* GI = Cast<UonwardGameInstance>(OwnerHUD->GetGameInstance());
	if (GI) { return GI->GetWorldTime()->GetTimeOfYear(); }
	return 0.5;
}

in the .cpp.

GetSeason() returns an FString with something like “Early Winter” or “Mid Fall” and is updating just fine.
GetTimeOfYear() returns a float in the range [0.0,1.0) and does not seem to be updating. In fact, I threw some breakpoints in and saw that GetWorldTimeOfYear is only being called once at the beginning of the level.

The two are used like so:


+ SVerticalBox::Slot() .Padding(6,2)
[
	SNew(SOverlay)
	+ SOverlay::Slot()
	[
		SNew(SProgressBar)
		.Percent(WorldTimeOfYear.Get())
	]
	+ SOverlay::Slot() .Padding(PADDING)
	
		SNew(STextBlock)
		.Text(WorldSeason)
		.ShadowColorAndOpacity(FLinearColor::Black)
		.ShadowOffset(FIntPoint(1, 1))
	]
]

I’m pretty sure that the problem has something to do with WorldTimeOfYear.Get(), but I don’t know what. Can anyone tell me what I’m doing wrong here?

I’ve figured it out:

GetWorldTimeOfYear() needs to return a TOptional<float>, and the progressbar needs to be defined like so: .Percent(this, &SStandardSlateWidget::GetWorldTimeOfDay)