Making DeltaTime in FRunnable

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

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

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

	}

}

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.

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