Skip to content

Component

A pattern that builds entities by splitting behavior into small units and composing them instead of relying on inheritance.

  • When character features need to be combined flexibly.
  • When the design must allow features to be enabled and disabled at runtime.
  • Entity: component container
  • Component: independent unit of behavior
  • Composer: initial composition setup

The code below is a simplified Unity example based on the scenario described above.

using System.Collections.Generic;
using UnityEngine;
public interface IGameComponent
{
void Tick(float deltaTime);
}
public sealed class MovementComponent : IGameComponent
{
private readonly Transform targetTransform;
private readonly float moveSpeed;
public MovementComponent(Transform targetTransform, float moveSpeed)
{
this.targetTransform = targetTransform;
this.moveSpeed = moveSpeed;
}
public void Tick(float deltaTime)
{
targetTransform.position += Vector3.forward * moveSpeed * deltaTime;
}
}
public sealed class CharacterControllerRoot : MonoBehaviour
{
private readonly List<IGameComponent> components = new();
private void Awake()
{
components.Add(new MovementComponent(transform, 5f));
}
}
  • You can split features into modular pieces and quickly create variations of characters and objects.
  • Since individual components can be tested or replaced, the regression surface stays smaller.
  • If dependencies between components grow, a new kind of coupling appears again.
  • If the update loop is scattered across many components, call overhead and debugging difficulty increase.

This shows the flow where an entity combines multiple components to produce the final state.

Component Flow