#Bullets Physics Bug
7 messages · Page 1 of 1 (latest)
https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Time-deltaTime.html
When this is called from inside MonoBehaviour.FixedUpdate, it returns Time.fixedDeltaTime. The maximum value for deltaTime is defined by Time.maximumDeltaTime.
Yes, I know this. But actually there are some edge conditions that may cause problems, usually when your FPS is lower than FixedUpdate execute frequency or there is a lot of objects need to Update. A typical situation is that FixedUpdate is executed multiple time in one frame, the value of Time.deltaTime can be buggy even called inside FixedUpdate, and even in a same execution
A example of this behavior:
[Info : Unity Log]
param: 0.03333667
deltaTime: 0.01666667
fixedDeltaTime: 0.01666667
[Error : Unity Log] Diff: 0.01666667
The test script is as follows:
public class TimeTest: MonoBehaviour
{
void FixedUpdate()
{
//Do some work
int i = 0;
for(int j = 0; j < 100; j++)
{
i = i + j;
}
Exec(i, Time.deltaTime);
}
void Exec(int i, float deltaTime)
{
Debug.Log($@"
param: {deltaTime}
deltaTime: {Time.deltaTime}
fixedDeltaTime: {Time.fixedDeltaTime}
");
if (deltaTime != Time.fixedDeltaTime)
{
Debug.LogError($"Diff: {deltaTime = Time.fixedDeltaTime}");
}
}
}