Result
Time.deltaTime=0.02
SystemAPI.Time.DeltaTime=0.00277
SystemAPI.Time.DeltaTime=0.002708292
SystemAPI.Time.DeltaTime=0.002532917
SystemAPI.Time.DeltaTime=0.002569916
SystemAPI.Time.DeltaTime=0.002836834
ECS’s delta time seems faster than MonoBehavior’s delta time. If both delta times do not exactly match, it will appear as speed racing. For example:
Frame1: speedTime.deltaTime = 0.124, speedSystemAPI.Time.DeltaTime = 0.127
Frame2: speedTime.deltaTime = 0.125, speedSystemAPI.Time.DeltaTime = 0.126
Frame2: speedTime.deltaTime = 0.127, speedSystemAPI.Time.DeltaTime = 0.125
…
So if you set the camera position with Time.deltaTime and set the player position with SystemAPI.Time.DeltaTime, in theory, the player and camera should have the same speed. But because of the deviation, the camera is sometimes behind a little bit, sometimes forward a little bit.
Pick one. Either or.
Passing UnityEngine.Time.deltaTime to the jobs is fine as long as other logic is using the same dT. As long as you call Time.deltaTime on the main thread that is. And vice-versa.
dT’s are based on previous frames, not the current. So it doesn’t matter how much time you call dT in the same frame - it will return the same value.
Time.DeltaTime should be more precise though, and doesn’t explode when too many time has passed since previous frames. I’d pick it if possible.
If you want to update MonoBehaviour in a system - you can always do that by attaching MonoBehaviour as [Add]ComponentObject to the entity. Then just query MonoBehaviour in a SystemBase as usually.
If you look into how dT’s for the TimeData computed you’ll see something like this:
var currentElapsedTime = SystemAPI.Time.ElapsedTime;
var deltaTime = math.min(UnityEngine.Time.deltaTime, World.MaximumDeltaTime);
World.SetTime(new TimeData(
elapsedTime: currentElapsedTime + deltaTime,
deltaTime: deltaTime
));
Perhaps math messes with the values, or maximum value is set too low and hitting threshold.
Or the framerate drops which causes dT to spike which is clamped against the threshold.
I tried to pass MonoBehavior’s delta time to ECS, but ECS will use MonoBehavior’s delta time multiple times, the reason is that in my example, ECS’ one-loop cycle is faster than MonoBehavior’s one-loop cycle, this will cause Camera has faster speed than Role.