Since a very important aspect of automated testing is determinism, this idea, if implemented, would allow to remove an important cause of non-determinism in automated game testing, that is Time.deltaTime and everything derived from it.
The idea would be a set of API calls that would allow to programmaticallly set Time.deltaTime (and thus derive other fields of Time from it) regardless of the time it actually took the system to render a given frame, which can allow us to run tests that will deterministically pass or fail regardless of the frame rate of the machine.
The API call should be able to take either a scalar constant value (âthis test runs at 60 fpsâ), a Func<int,float> (the int parameter being the frame number from the moment you call the function) or an IEnumerator to be able to set either a seeded-prng formula, or to simulate an fps drop at a given time. There would need to be some function to reset the deltaTime to its default behaviour and/or some scoping mechanism to make sure that it doesnât affect the entire editor session (I am not an expert in C#/Unity internals myself, I am sure the devs would figure out how to scope it).
2 Likes
We actually already have a facility for this: Unity - Scripting API: Time.captureDeltaTime
2 Likes
Thanks a lot for your prompt reply. I guess this would work (even though the use case mentioned in the docs isnât the same as the testing use case I mentioned). First of all, this mentions it affects Time.time, but does it affect Time.deltaTime, since itâs what most game components would use to compute their motion? Also, do any standard provided components use Time.unscaledTime?
[quote=âNabilStendardo, post:3, topic: 840468, username:NabilStendardoâ]
Thanks a lot for your prompt reply. I guess this would work (even though the use case mentioned in the docs isnât the same as the testing use case I mentioned).
[/quote]Yeah, the documentation is a bit focused on the âvideo captureâ use case, but it should be applicable to any situation where you want a deterministic time-per-frame.
[quote]
First of all, this mentions it affects Time.time, but does it affect Time.deltaTime, since itâs what most game components would use to compute their motion?
[/quote]Yes, it affects Time.deltaTime too.
[quote]
Also, do any standard provided components use Time.unscaledTime?
[/quote]Some components can be configured to - for example the Animator component can be configured with updateMode = AnimatorUpdateMode.UnscaledTime
. I think for those components youâd want to modify them as part of test setup to use Normal mode instead, which would make them subject to Time.deltaTime.