How to get FixedUpdate (fixed frame) count since startup?

I am trying to implement a delay system that is based on fixed frames.

There doesn’t seem to be a “fixed frame” equivalent for Time.frameCount

How can I get the number of fixed updates since the start of the game?

Is Time.fixedTime / Time.fixedDeltaTime a viable solution? (I think it could fail in some [rare?] situations?)

Can’t you just create your own counter? Something like this:

int frameCounter;
void Start()
{
frameCounter=0;
}

void FixedUpdate()
{
frameCounter++;
}

Have you considered creating a class called Delay or something similar, looking something like this

float fixedFrames = 0;



	public static float getFixedFrames(){
		return fixedFrames;
	}

	void FixedUpdate () {
		fixedFrames++;
	}

I see no problem with doing something like that, you could even slot that into any class and that sould work.

Hi, do you mean something like Time.timeSinceLevelLoad ? Otherwise you could increase some float variable: timeSinceStart += Time.fixedDeltaTime; in your FixedUpdate() function. If you wanna calculate the time since startup through scenes you could use a static float variable.

To get the fixed frame count you just have to divide Time.fixedTime by Time.fixedDeltaTime as you have discovered. However since those are floating point numbers the result might be slightly off. You can use Mathf.RoundToInt to get an actual integer value.

public static int FixedFrameCount()
{
    return Mathf.RoundToInt(Time.fixedTime / Time.fixedDeltaTime);
}

This might get inaccurate after a longer playtime due to the dynamic accuracy range of floating point numbers but should be ok for quite a long period of time. So if you need an more “reliable” count you might want to count manually as the others have shown.