What Is It?
A game world is full of things that act independently: coins bob, turrets turn, projectiles fly, timers count down. The Update Method pattern gives each of them a method that does one frame of work, and a loop that calls that method on every live object once per frame. Nobody has to know what the others are doing.
Unity is built on this idea. Every MonoBehaviour with an Update() is registered with the engine and called each frame. That is convenient, but each of those calls crosses from native engine code into managed C#, and with thousands of tiny components that per-call overhead (plus the engine iterating and null-checking each behaviour) adds up before any of your logic runs.
The game-programming version makes the list explicit: an IUpdatable interface with Tick(float dt), and one UpdateManager whose single Update() walks a List<IUpdatable>. One native-to-managed call per frame instead of one per object, a defined order, and an obvious place to pause, slow down or profile a whole group of entities.
When Is It Used?
Use it whenever a set of objects each need small, independent per-frame behaviour: ambient props, pickups, projectiles, AI agents that think a little every frame, cooldown timers.
Switch from per-object Update() to a manager when the profiler shows many hundreds of tiny Update calls, when you need a deterministic order between entities, or when you want to pause, time-scale or LOD a whole category (for example, tick far-away enemies every fourth frame).
Do not use it for things that only react to events, or that change rarely. A door that opens once should not be asked "anything to do?" sixty times a second; let an event or a coroutine wake it up.
Interactive Demo
Click the controls and watch the objects collaborate. The console mirrors what the C# code below would log.
Code
using UnityEngine;
namespace Patterns.GameProgramming.UpdateMethod
{
/// <summary>
/// Entry point: fills the scene with spinners. None of them owns an
/// Update(); a single UpdateManager ticks them all.
/// </summary>
public class SpinnerSpawner : MonoBehaviour
{
[SerializeField] private Spinner prefab;
[SerializeField] private int count = 1000;
[SerializeField] private float radius = 20f;
private void Start()
{
for (int i = 0; i < count; i++)
{
Vector2 p = Random.insideUnitCircle * radius;
Instantiate(prefab, new Vector3(p.x, p.y, 0f), Quaternion.identity, transform);
}
Debug.Log($"Spawned {count} spinners, {UpdateManager.Instance.Count} registered for Tick");
}
private void Update()
{
// Spawning from inside a frame is fine too: Register is deferred while ticking.
if (Input.GetKeyDown(KeyCode.Space))
Instantiate(prefab, transform.position, Quaternion.identity, transform);
}
}
}using System.Collections.Generic;
using UnityEngine;
namespace Patterns.GameProgramming.UpdateMethod
{
/// <summary>
/// One MonoBehaviour.Update that ticks every registered object.
/// Registering and unregistering during a tick is safe: changes are
/// queued and applied before the next pass over the list.
/// </summary>
[DefaultExecutionOrder(-100)]
public class UpdateManager : MonoBehaviour
{
public static UpdateManager Instance { get; private set; }
private readonly List<IUpdatable> active = new();
private readonly List<IUpdatable> pendingAdd = new();
private readonly HashSet<IUpdatable> pendingRemove = new();
private bool ticking;
public int Count => active.Count;
private void Awake() => Instance = this;
private void OnDestroy()
{
if (Instance == this) Instance = null;
}
public void Register(IUpdatable item)
{
if (ticking) { pendingRemove.Remove(item); pendingAdd.Add(item); }
else if (!active.Contains(item)) active.Add(item);
}
public void Unregister(IUpdatable item)
{
if (ticking) { pendingAdd.Remove(item); pendingRemove.Add(item); }
else active.Remove(item);
}
private void Update()
{
float dt = Time.deltaTime;
ticking = true;
for (int i = 0; i < active.Count; i++)
{
IUpdatable item = active[i];
if (!pendingRemove.Contains(item))
item.Tick(dt);
}
ticking = false;
// Apply structural changes only after the loop has finished.
if (pendingRemove.Count > 0) { active.RemoveAll(pendingRemove.Contains); pendingRemove.Clear(); }
foreach (IUpdatable item in pendingAdd)
if (!active.Contains(item)) active.Add(item);
pendingAdd.Clear();
}
}
}namespace Patterns.GameProgramming.UpdateMethod
{
/// <summary>
/// Anything that wants to advance by one frame. The manager calls Tick
/// once per frame; the object decides what one frame of its life means.
/// </summary>
public interface IUpdatable
{
void Tick(float deltaTime);
}
}using UnityEngine;
namespace Patterns.GameProgramming.UpdateMethod
{
/// <summary>
/// A small entity with no Update() of its own. It registers with the
/// manager while enabled and does one frame of work per Tick.
/// </summary>
public class Spinner : MonoBehaviour, IUpdatable
{
[SerializeField] private float degreesPerSecond = 180f;
[SerializeField] private float lifetime = 5f;
private float age;
private void OnEnable()
{
age = 0f;
UpdateManager.Instance.Register(this);
}
private void OnDisable()
{
if (UpdateManager.Instance != null)
UpdateManager.Instance.Unregister(this);
}
public void Tick(float deltaTime)
{
transform.Rotate(0f, 0f, degreesPerSecond * deltaTime);
age += deltaTime;
if (age >= lifetime)
gameObject.SetActive(false); // unregisters mid-tick: safe, it is deferred
}
}
}Before & After
Real-world smell: eight hundred coins that each own an update callback. Here is the code without the pattern, the refactored version, and the exact diff between them.
! What’s wrong with it?
Coin has its own Update() that bobs and spins the coin. The level has 800 of them, so Unity makes 800 separate native-to-managed calls every frame for a few lines of math each.
In the profiler this shows up as a long list of tiny Coin.Update entries plus engine overhead around them. There is also no single place to pause the coins during a cutscene or to stop ticking the ones far from the camera.
✓ What changed
Coinnow implementsIUpdatable, and its oldUpdate()body moved unchanged intoTick(float dt).- The coin registers with
UpdateManager.InstanceinOnEnableand unregisters inOnDisable, so collecting it withDestroystops its ticks automatically. - Because
UpdateManagerdefers removals during a tick, callingCollect()from inside another entity’sTickcannot corrupt the list.
using UnityEngine;
namespace Patterns.GameProgramming.UpdateMethod
{
/// <summary>
/// Without a central tick: each of the 800 coins in the level owns a
/// Unity Update() just to bob and spin a little.
/// </summary>
public class Coin : MonoBehaviour
{
[SerializeField] private float spinSpeed = 90f;
[SerializeField] private float bobHeight = 0.25f;
[SerializeField] private float bobSpeed = 2f;
private Vector3 origin;
private float phase;
private void Awake()
{
origin = transform.localPosition;
phase = Random.value * Mathf.PI * 2f;
}
private void Update()
{
float dt = Time.deltaTime;
phase += bobSpeed * dt;
transform.localPosition = origin + Vector3.up * (Mathf.Sin(phase) * bobHeight);
transform.Rotate(0f, spinSpeed * dt, 0f);
}
public void Collect()
{
Destroy(gameObject);
}
}
}using UnityEngine;
namespace Patterns.GameProgramming.UpdateMethod
{
/// <summary>
/// With Update Method: the coin implements Tick and lets one
/// UpdateManager drive all 800 coins from a single Update().
/// </summary>
public class Coin : MonoBehaviour, IUpdatable
{
[SerializeField] private float spinSpeed = 90f;
[SerializeField] private float bobHeight = 0.25f;
[SerializeField] private float bobSpeed = 2f;
private Vector3 origin;
private float phase;
private void Awake()
{
origin = transform.localPosition;
phase = Random.value * Mathf.PI * 2f;
}
private void OnEnable() => UpdateManager.Instance.Register(this);
private void OnDisable()
{
if (UpdateManager.Instance != null)
UpdateManager.Instance.Unregister(this);
}
public void Tick(float dt)
{
phase += bobSpeed * dt;
transform.localPosition = origin + Vector3.up * (Mathf.Sin(phase) * bobHeight);
transform.Rotate(0f, spinSpeed * dt, 0f);
}
public void Collect()
{
// OnDisable unregisters; safe even if this runs inside another Tick.
Destroy(gameObject);
}
}
}Advantages & Disadvantages
+ Advantages
- Each entity owns its own behaviour, so adding a new kind of object never touches a central
switchstatement. - A manager replaces thousands of engine callbacks with one, and gives you a single place to profile, pause or throttle updates.
- Iteration order becomes explicit and controllable instead of depending on Script Execution Order settings.
− Disadvantages
- Adding or removing entities while iterating the list skips items, ticks something twice or throws
InvalidOperationException. You need deferred add/remove. - Every entity is polled every frame even when it has nothing to do, which wastes time on idle objects.
- A hand-rolled manager must mirror enable/disable correctly; a disabled object that forgets to unregister keeps ticking or holds a dead reference.
Tips
- 01Register in
OnEnableand unregister inOnDisablesoSetActive(false)andDestroyboth stop the ticks automatically. - 02Never mutate the list inside the loop. Queue adds and removals in
pendingAdd/pendingRemoveand apply them after the pass, or iterate a copy if the list is small. - 03Pass
Time.deltaTimeintoTickso every entity uses the same value and you can feed a scaled or paused delta for a whole group. - 04Empty
Update()methods still cost a call each frame. Delete them, including the ones Unity’s script template creates. - 05Measure first. A manager pays off with hundreds or thousands of small updaters; for twenty objects, plain
Update()is clearer and just as fast.