GetWorld()->GetRealTimeSeconds() from ULocalPlayer is completely wrong

I don’t what is wrong with the GetRealTimeSeconds() function from the GetWorld() called from the ULocalPlayer.

I call the function several times and the function returns strange values.
As you can see in the log, the time is accurate at the first call, but then the value is completely wrong.

[2017.02.13-13.37.03:709][988]LogOnline:Verbose: UKLocalPlayer::StartMatch - GetWorld()->GetRealTimeSeconds()=16.379499
[2017.02.13-13.37.06:482][140]LogOnline:Verbose: UKLocalPlayer::StartMatch - GetWorld()->GetRealTimeSeconds()=1.181171
[2017.02.13-13.37.09:105][282]LogOnline:Verbose: UKLocalPlayer::StartMatch - GetWorld()->GetRealTimeSeconds()=1.008759
[2017.02.13-13.37.28:920][477]LogOnline:Verbose: UKLocalPlayer::StartMatch - GetWorld()->GetRealTimeSeconds()=1.562432
[2017.02.13-13.37.43:307][350]LogOnline:Verbose: UKLocalPlayer::StartMatch - GetWorld()->GetRealTimeSeconds()=1.465323

Is there something special with this function ?

The call to the function GetWorld()->GetTimeSeconds() returns always 0.

D.

I think I have an explanation about this distortion.

The ULocalPlayer GetWorld function takes the world from the viewport.
When the player travel to another map, the world is created, therefore the time is reset.

UWorld* ULocalPlayer::GetWorld() const
{
	return ViewportClient ? ViewportClient->GetWorld() : nullptr;
}

UWorld* UGameViewportClient::GetWorld() const
{
	return World;
}

I need the realtime since the game was started and not the one since the player travel to any map.

D.

Hey domzorg,

Would it be possible for you to try using UGameplayStatics::GetRealTimeSeconds() instead?

I will try. But now I’m stuck in migrating to 4.15
I let you know as soon as I will be able to compile the code with the 4.15 version.

Sounds good, feel free to leave a comment to reopen the thread once you’re able to test it out.

I’m back.
I’ve understood my problem.
The GetTimeSeconds function is related to the loaded world.
What is the equivalent function to obtain the time since the game started ?

To solve my problem, and not being linked to the world, I use the FPlatformTime::Seconds(). And it works.