All work

Breakdown · Solo project

Unicellular

Feb 2025 · Unity · C# · Released on itch.io

An idle simulation built around sheer entity count: thousands of single celled organisms wandering, interacting and multiplying, kept smooth by a 20 Hz behaviour tick, a 0.5 Hz bookkeeping tick and proximity checks swept about 150 cells at a time.

  • Stress test10,000 cells
  • Behaviour tick20 Hz
  • Bookkeeping tick0.5 Hz
  • Proximity pass~150 cells

Overview

An idle game built to scale

Unicellular is an idle sim: you spend currency to buy unicells, they drift around a petri dish living their tiny lives, and the colony's activity feeds the economy back to you. The design means the player is directly incentivised to push the entity count up, so each cell has to stay cheap to simulate or the game's own core loop kills its framerate.

Behaviour is driven by lightweight finite state machines, and the saving comes from when work runs: instead of every cell thinking every frame, the simulation is split across several tick rates and the expensive proximity checks are spread out a batch at a time, all inside Unity's standard GameObject workflow. This is the second build of the game: I restarted it around one manager that drives every cell, an idea borrowed from ECS, once the first version's per cell updates ran out of room.

On top of the simulation sits a full idle-game economy: seven species of cell, layered upgrades, rare Elder and Shiny variants, a per-species "Souls" prestige currency, and JSON saves so a colony survives between sessions.

The core loop: buy cells, grow the colony, earn faster.

Behaviour

One FSM per cell

Every unicell runs a small finite state machine, moving between states such as Idle, Hungry, Fighting, Fleeing and Reproducing. Each state is tiny and each transition is explicit, so the cost of a cell "thinking" stays roughly constant however big the colony gets.

With thousands of these running side by side, the dish looks busy without any one cell doing anything complicated. The decision itself is a few lines:

Assets/Scripts/Managers/UnicellManager/EntityManager.cs a neighbour in range means fight; otherwise heal if hurt, and look for food if not
void DecideUnicellState(Unicell unicell)
{
    // Fight, Idle, Flee, Hungry, Reproduce

    if (unicell.NearestUnicell != null)
    {
        if (/*unicell.CurrentHealth < unicell.MaxHealth / 5f*/ false)
        {
            ChangeState(unicell, UnicellState.Fleeing); // Shows a fear of death from Unicells, even if inevitable it would still make them feel more sentient and convincing
        }
        else
        {
            ChangeState(unicell, UnicellState.Fighting); 
        }
    }
    else
    {
        if (unicell.CurrentHealth < unicell.MaxHealth)
        {
            ChangeState(unicell, UnicellState.Idle); // Idle regenerates health
        }
        else
        {
            ChangeState(unicell, UnicellState.Hungry); // Default behaviour
        }
    }
}

The excerpt also shows something the list of states hides. Fleeing still has its own state code, but the health check that chooses it is switched off, so a cell with a neighbour in range always fights.

Cells interacting; each side of the exchange is a state transition.

Performance

Stress tested at 1,000 and 10,000

The recordings below are the two benchmark scenes: a thousand cells, then ten thousand at once, where the counter in the second clip is still reading around 90 FPS. Both were recorded in the Unity editor, not a build, on a Ryzen 7 7800X3D with an RTX 4070 and 32 GB of RAM. That headroom is what lets the idle economy keep rewarding a bigger colony without the framerate collapsing.

The main levers:

  • A decoupled, multi-rate loop. Core behaviour ticks at 20 Hz, slower bookkeeping like population and levelling runs at 0.5 Hz, and physics work sits in its own pass, so nothing runs more often than it needs to.
  • Time-sliced proximity AI. The expensive "what is near me" queries are the bottleneck, so they are amortised across frames: roughly 150 cells are processed per pass, carrying an index forward until the whole colony has been swept.
  • One manager, not thousands of updates. A single simulation manager iterates the cell and food lists directly instead of every cell running its own per-frame update.

The two rates are just two independent accumulators, and the slicing falls out of one flag. When the slow tick fires it clears isProximityUpdateComplete and starts a batch; every FixedUpdate after that continues the sweep until the colony has been covered, so the cost of a proximity pass is spread over however many frames it needs rather than landing in one.

Assets/Scripts/Managers/UnicellManager/EntityManager.cs the fast tick, the slow tick, and the sweep continuing across frames
void Update()
{
    LogicUpdateTimer += Time.deltaTime;
    if (LogicUpdateTimer > LogicUpdateTimerThreshold)
    {
        LogicUpdateTimer -= LogicUpdateTimerThreshold;
        LogicUpdate();
    }

    SlowLogicUpdateTimer += Time.deltaTime;
    if (SlowLogicUpdateTimer > SlowLogicUpdateTimerThreshold)
    {
        SlowLogicUpdateTimer -= SlowLogicUpdateTimerThreshold;
        isProximityUpdateComplete = false;
        ProximityBatchUpdate();
        SlowLogicUpdate();

        CheckUnicellsForHunger();
    }
}
void FixedUpdate()
{
    if (!isProximityUpdateComplete)
    {
        ProximityBatchUpdate();
    }

    // ... per-cell movement omitted
}
Assets/Scripts/Managers/UnicellManager/EntityManager.cs one batch: a carried index, capped at the end of the list, and the flag that ends the sweep
void ProximityBatchUpdate()
{
    // Determines end index for this batch
    int endIndex = Mathf.Min(currentIndex + ProximityBatchSize, unicellList.Count);

    // Updates the batch of unicells
    for (int i = currentIndex; i < endIndex; i++)
    {
        Unicell unicell = unicellList[i];

        // ... growth omitted

        if (unicell.CurrentState == UnicellState.Hungry)
        {
            Food NewNearestFood = FindNearestFood(unicell, unicell.ProximityRadius);
            // ... keep it if it is new
        }

        Unicell NewNearestUnicell = FindNearestUnicell(unicell, unicellList[i].ProximityRadius);
        // ... keep it if it is new

        DecideUnicellState(unicell);
    }

    // Updates current index
    currentIndex = endIndex;

    // Resets current index if it reaches the end of the list
    if (currentIndex >= unicellList.Count)
    {
        currentIndex = 0;
        isProximityUpdateComplete = true;
    }
}

The two FindNearest calls do not loop over every other cell. Each asks Physics2D.OverlapCircleAll for the colliders inside that cell's own radius, so the physics engine's broadphase does the spatial work, and the batch decides how many of those queries a frame pays for.

The smaller benchmark: 1,000 entities. The ten thousand run is the clip at the top of this page.

In hindsight

What I'd change

Everything above keeps a GameObject workflow fast by working around its costs: batching the ticks, slicing the proximity queries, collapsing thousands of updates into one manager. Those are the right moves inside that architecture, but they are still workarounds.

If I built this again I would use Unity's Entity Component System instead. Laying the data out contiguously and letting jobs run over it is the thing this simulation actually wants, and it should take the entity ceiling well past ten thousand rather than making ten thousand survivable. I would learn ECS properly rather than reaching for it as a label, and I would start from the profiler rather than the rewrite: the proximity sweep is the measured bottleneck, so that is the system that earns the change first.