# Making DeltaTime in FRunnable

**URL:** <https://forums.unrealengine.com/t/making-deltatime-in-frunnable/1771151>\
**Category:** C++\
**Tags:** threads, async, multithreading, unreal-engine, question, CPP\
**Created:** [March 25, 2024, 8:34am UTC](https://forums.unrealengine.com/t/making-deltatime-in-frunnable/1771151 "2024-03-25T08:34:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CookieSakje](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CookieSakje](https://forums.unrealengine.com/u/CookieSakje)\
**Post date:** [March 25, 2024, 8:34am UTC](https://forums.unrealengine.com/t/making-deltatime-in-frunnable/1771151/1 "2024-03-25T08:34:35Z")

</div>

```auto
std::chrono::steady_clock::time_point PreviousTime;

//
uint32 FTestThread
{
while(!Stop)
{
		const std::chrono::steady_clock::time_point tClock_Start = std::chrono::steady_clock::now();
		const double DeltaTime = std::chrono::duration_cast<std::chrono::nanoseconds> (tClock_Start - PreviousTime).count() * 10e-9;
		PreviousTime = tClock_Start;

		//Doing something here

		FPlatformProcess::Sleep(0.01);
	}

	return 0;
}

```

The DeltaTime always remains at 0.

I’ve tried changing the std::chrono::(timetype) and the scalar (1e-9) on std::chrono::duration\_cast, but it still returns the same.

Is there anything I should know to make DeltaTime functional in FRuunable?

Please suggest other method or solution

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [March 25, 2024, 9:42am UTC](https://forums.unrealengine.com/t/making-deltatime-in-frunnable/1771151/2 "2024-03-25T09:42:09Z")

</div>

Edit:

Ok so you can use FApp to get the delta time directly from within the worker class

includes needed: #include “Misc/App.h”

then you can call the static method FApp::GetDeltaTime(); from within your worker function to get the deltatime as a double (can be cast to a float if you want it to mirror the ingame dt format).

* * *

older suggestion:

Have you considered passing in the game deltatime in the worker manager actor tick?

where AMyClass would be the manager class and Worker is the FRunnable inherited class

```auto
void AMyClass::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (Worker)
	{
			Worker->DeltaTime = DeltaTime; // passing in the delta time from game thread

			UE_LOG(LogTemp, Warning, TEXT("Game thread: deltaTime gotten from worker thread: %f"), Worker->DeltaTime) // retrieving the delta time from the frunnable and printing it

	}

}

```

---

<div class="post-metadata">

**Author:** ![CookieSakje](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CookieSakje](https://forums.unrealengine.com/u/CookieSakje)\
**Post date:** [March 25, 2024, 10:12am UTC](https://forums.unrealengine.com/t/making-deltatime-in-frunnable/1771151/3 "2024-03-25T10:12:00Z")

</div>

Thank you for your help.  
However I don’t think it’s possible to safely obtain DeltaTime within the thread using this method. I want to calculate DeltaTime using the thread independent of the game thread.

---

<div class="post-metadata">

**Author:** ![CookieSakje](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CookieSakje](https://forums.unrealengine.com/u/CookieSakje)\
**Post date:** [March 25, 2024, 10:16am UTC](https://forums.unrealengine.com/t/making-deltatime-in-frunnable/1771151/4 "2024-03-25T10:16:26Z")

</div>

I tested it, but I found that DeltaTime is twice as slow as I expected.
