Skip to main content

Fixed-step input for Unity

My Fixed Tick

One press, one fixed step.

LicenseMIT
Unity6.0+
DependenciesNone
EntitiesOptional
Intent sizeTwo fields · Burst-ready

An intent instead of a flag

Write and read input like this:

// A writer, wherever input comes from.
input.Attack.Set(MyFixedTick.Current);

// A reader, later in the same step.
if (input.Attack.TryConsume(tick))
Attack();

Instead of:

bool _attackPressed;

void Update()
{
if (Keyboard.current.jKey.wasPressedThisFrame)
_attackPressed = true;
}

void FixedUpdate()
{
if (_attackPressed)
{
_attackPressed = false;
Attack();
}
}

The flag stays set until something clears it, so a paused game delivers a stale press and a second reader never sees it. An intent is valid for exactly one fixed step and expires by arithmetic.

One surface, any writer

Put a project's input vocabulary in a plain type, and have every reader read only that.

public class CharacterInput : MonoBehaviour
{
public Vector2 Move; // continuous
[FixedInputWindow(5)] public FixedInputEvent Attack; // discrete, lenient
public FixedInputEvent Evade; // discrete, frame-exact
}
  • A keyboard writes it

    A device writer stamps each press with the current tick, from Update or FixedUpdate.

  • So does a script

    A scripted agent fills the same fields. Nothing distinguishes it from a player.

  • The reader can't tell

    It reads only the surface, so every mechanic written for a player works for an agent the day it ships.

Expires by arithmetic

Nothing clears an intent and nothing consumes it twice. A paused or reloaded game cannot deliver a stale press.

A tick that installs itself

The default clock joins the end of the fixed phase. No scene object, no prefab, no script execution order.

Buffering per read

The window is an argument to each read, so one press can be frame-exact for one reader and lenient for another.

Bring your own clock

ITickSource is an interface. Run off a netcode tick, a lockstep frame or a manual clock in tests.

Diagnostics that name it

The editor reports an intent nobody consumed and two writers that fought over a field, by name and call site.

Entities, if you want it

Two unmanaged fields, so an intent drops into an IComponentData. The ECS clock compiles only when Entities is installed.

Install it

Choose your preferred installation method.