DeltaTime and FPlatformTime

I took another challenge and tried to count ReloadTime (3,2,1)
At first I want to resolve this issue by the DeltaTIme:

void UTankAimingComponent::TimeComponent()
{
   myDelta = myDelta + DeltaTime;
   RoundLeft = RoundLeft - int(myDelta);  // RoundLeft = 3

this code don’t work myDelta collect the DeltaTime correctly but RoundLeft subtract myDelta significantly faster
when myDelta equaled 3,
RoundLeft was approximately -150

Then I sovled this problem by FPlatformTime::Second()

if (FPlatformTime::Seconds() - LastFireTime < ReloadTimeInSeconds)
{
	FiringState = EFiringState::Reloading;
    RoundLeft = 1+ReloadTimeInSeconds + LastFireTime - FPlatformTime::Seconds();

Can Somebody explain me why FPlatformTime works and DeltaTime is not ?
and why DeltaTIme’s behaviour is so strange ?

FPlatformTime counts normal time since a specific moment, a certain date or the time you turned or installed your pc or something, basically its a normal time counting function.
DeltaTime on the other hand is a Time component that is basically the time that each frame takes to work, so it is heavily influenced by your computers performance, the optimization of your own code etc.

Thank you for your opinion this post is older but as I remember the problem was subtract
I know difference Delta time and Normal time. In my code I collect Delta time in member variable myDelta and then it is subtracted also member variable Roundleft = 3.
and I get such case when myDelta = 3 Roundleft = -150. this is my question why I get such strange result ?

hmm I can try to guess that since its called every frame that your mydelta got called a lot of times very quickly and if you didn’t reset or limit it somewhere else in the code it might have just gone overboard with its own iterations.

Privacy & Terms