Having trouble understanding FTimeSpan's behavior

I’m trying to work out a way to use an FDateTime variable as my in-game clock, by taking the DeltaTime every tick, multiplying it by whatever real time/game time conversion factor I want, and adding that to the FDateTime. I’ve already gathered that you modify datetime objects with FTimeSpan, so I expected the following to work:


	FTimespan modifyTime;
	modifyTime = modifyTime.FromMilliseconds(DeltaTime);
	dateTime += modifyTime;

The above code never advances the clock, which initially made me assume that I simply couldn’t work in milliseconds. However, the following change does work, and as far as I can tell it causes the clock to keep correct time:



	FTimespan modifyTime;
	modifyTime = modifyTime.FromSeconds(DeltaTime);
	dateTime += modifyTime;

However, I’m hesitant to use it without understanding it- DeltaTime is a float that measures the time between frames, shouldn’t I be processing it as milliseconds, not seconds?

No, [FONT=Courier New]DeltaTime is actually the time since the last tick in seconds. The documentation for some overloads of [FONT=Courier New]Tick indicates this by using [FONT=Courier New]DeltaSeconds as parameter name, see, e.g., [FONT=Courier New]AActor::Tick](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/Tick/1/index.html). You can also check this by comparing your tick delta with the difference between the wall clock times of the previous and current frame:


void ATickingActor::Tick( float DeltaTime )
{
	Super::Tick(DeltaTime);
	static int32 PreviousMilliseconds{ FDateTime::Now().GetMillisecond() };

	int32 CurrentMilliseconds{ FDateTime::Now().GetMillisecond() };
	if (CurrentMilliseconds < PreviousMilliseconds)
	{
		PreviousMilliseconds -= 1000;
	}
	int32 ElapsedMiliseconds{ CurrentMilliseconds - PreviousMilliseconds };
	PreviousMilliseconds = CurrentMilliseconds;

	UE_LOG(LogTemp, Log, TEXT("Ticking: Delta Time = %f, Elapsed Time = %dms"), DeltaTime, ElapsedMiliseconds);
}


This results in output of the form


LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 8ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 8ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 9ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 8ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 8ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 9ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 8ms
LogTemp: Ticking: Delta Time = 0.008333, Elapsed Time = 8ms


Ooh no wonder, I hadn’t even thought to test that, thank you! :slight_smile: