Unity Architecture: ScriptableObjects, DI and ECS, When to Use Each
Unity architecture without over-engineering: MonoBehaviours plus ScriptableObjects first, DI when the project grows, ECS only for thousands of objects.

The best Unity architecture for most games is the simplest one that stays testable: MonoBehaviours for behaviour in the scene, ScriptableObjects for data and configuration, plain C# classes for logic that does not need the scene, and tests around that logic. Add a dependency injection container such as VContainer or Zenject only when the project grows to the point where wiring references by hand hurts. Reach for ECS (Unity's Entities package, part of DOTS) only when you simulate thousands of similar objects and the Profiler proves GameObjects are the bottleneck. In our experience, most projects that start with all three on day one ship later, not faster.
This guide explains what each tool solves, what it costs, and how to decide, with short C# examples. It also covers a newer requirement: in 2026 a lot of Unity code is written or edited by AI agents, and an architecture the agent can read and verify with tests is worth more than a clever one. Facts about Unity and packages are as of November 2026.
The Three Layers in One Picture
Think of a Unity project as three layers that you add only when you need them.
- Layer 1, always: MonoBehaviours plus ScriptableObjects. Scenes, prefabs and components hold behaviour; ScriptableObject assets hold tuning data, configuration and shared definitions. Logic that does not touch the scene lives in plain C# classes.
- Layer 2, when the project grows: a DI container that builds the plain C# services and hands them to the components that need them, instead of singletons and FindObjectOfType calls.
- Layer 3, only for scale: ECS for the hot part of the simulation (bullets, crowds, boids, particles with gameplay), while the rest of the game stays on GameObjects.
The layers are not competing philosophies. A shipped game can use all three: GameObjects for the player, UI and menus, ScriptableObjects for every number a designer tunes, a container for services, and one ECS world for ten thousand projectiles. The mistake is adopting layer 2 or 3 before the problem it solves exists.
Layer 1: MonoBehaviours and ScriptableObjects
A ScriptableObject is a data container saved as an asset in the project. It lives outside any scene, so many prefabs can reference the same asset, designers can edit values in the Inspector without touching code, and changes made in Play Mode in the Editor stay in the asset (a useful property for tuning, and a trap if you store runtime state there).
Our default recommendation: put every tunable number and every definition (enemy types, weapons, waves, items, level settings) into ScriptableObjects, and keep MonoBehaviours thin.
using UnityEngine;
[CreateAssetMenu(menuName = "Game/Enemy Definition")]
public class EnemyDefinition : ScriptableObject
{
[Min(1)] public int maxHealth = 100;
[Min(0f)] public float moveSpeed = 3.5f;
public int scoreReward = 10;
public GameObject prefab;
}The component reads its definition and delegates the rules to a plain C# class:
using UnityEngine;
public class Enemy : MonoBehaviour
{
[SerializeField] EnemyDefinition definition;
Health _health;
void Awake() => _health = new Health(definition.maxHealth);
public void TakeDamage(int amount)
{
if (_health.Apply(amount))
Destroy(gameObject);
}
}
// Plain C#: no scene, no Unity lifecycle, easy to test.
public class Health
{
public int Current { get; private set; }
public Health(int max) => Current = max;
// Returns true when this hit was lethal.
public bool Apply(int damage)
{
if (Current <= 0 || damage <= 0) return false;
Current = Mathf.Max(0, Current - damage);
return Current == 0;
}
}That split is the core of the whole article. The MonoBehaviour knows about the scene; the Health class knows about the rules. The rules can now be tested in milliseconds without loading a scene.
ScriptableObject Patterns That Work, and One to Use Carefully
- Definitions and configs: the example above. Safe, simple, and the biggest win.
- Shared runtime sets: a ScriptableObject that keeps a list of active enemies, so a spawner and a HUD can both see it without referencing each other. Clear the list in OnDisable or when a level loads.
- Event channels: a ScriptableObject with a C# event that one component raises and others listen to. It removes hard references between systems, which is good, but it also hides who calls whom. Use it for a handful of global events (player died, level completed), not as the default way every component talks.
- Avoid: mutable game state in ScriptableObjects without a reset. Values written in Play Mode persist in the Editor and do not persist in a build, which produces bugs that only appear on one side.
When Layer 1 Is Enough
If your game has one or two scenes, one programmer or a small team, and a few dozen scripts, layer 1 is the whole architecture. Serialized references in the Inspector are a form of dependency injection already: the scene is the composition root. Do not replace it with something that the team or the AI agent then has to learn.
Layer 2: Dependency Injection in Unity
Signs that the project has outgrown hand wiring:
- Singletons multiply (GameManager.Instance, AudioManager.Instance, SaveSystem.Instance), and the order in which they initialise starts to cause bugs.
- Tests need the whole scene because services are found with FindObjectOfType or static access.
- The same service must exist once per scene or per session, and you write lifetime code by hand.
- Several programmers add services and nobody knows where an object is created.
At that point a DI container pays for itself. The two common choices for Unity:
- VContainer: small and fast. Its README claims it is roughly 5 to 10 times faster than Zenject at resolving and allocates nothing during resolve when no instances are created. It supports Unity 2018.4 and newer, entry points that run plain C# classes on Unity's player loop, and nested scopes for scenes. Version 1.19.0 is the latest release on GitHub as of November 2026. Our pick for new projects.
- Zenject, and Extenject, its community fork: older, more features (signals, memory pools, factories, a large body of tutorials) and more concepts to learn. A reasonable choice if the team already knows it or the project already uses it.
A VContainer setup is one LifetimeScope component in the scene:
using UnityEngine;
using VContainer;
using VContainer.Unity;
public class GameLifetimeScope : LifetimeScope
{
[SerializeField] GameSettings settings; // a ScriptableObject asset
protected override void Configure(IContainerBuilder builder)
{
builder.RegisterInstance(settings);
builder.Register<ScoreService>(Lifetime.Singleton);
builder.Register<SaveService>(Lifetime.Singleton);
builder.RegisterEntryPoint<WaveDirector>(); // plain C#, gets Start/Tick
builder.RegisterComponentInHierarchy<PlayerHud>(); // existing MonoBehaviour
}
}Services take their dependencies through the constructor, and MonoBehaviours through an injected method:
using VContainer;
using VContainer.Unity;
public class WaveDirector : IStartable, ITickable
{
readonly GameSettings _settings;
readonly ScoreService _score;
public WaveDirector(GameSettings settings, ScoreService score)
{
_settings = settings;
_score = score;
}
public void Start() { /* spawn the first wave */ }
public void Tick() { /* advance timers, check win condition */ }
}
public class PlayerHud : UnityEngine.MonoBehaviour
{
ScoreService _score;
[Inject]
public void Construct(ScoreService score) => _score = score;
}Notice that ScriptableObjects do not disappear in layer 2. The settings asset is still the place where designers tune numbers; the container just delivers it.
What DI Costs
- One more concept for every new team member, and for every AI agent working in the project. "Where is this object created?" now has the answer "in the scope", which is only obvious if you know to look there.
- Errors move from compile time to the moment the container resolves: a missing registration is a runtime exception when the scene starts.
- Over-abstraction: an interface for every class "in case we swap it" doubles the files to read. Introduce an interface when you have two implementations or a test that needs a fake, not before.
Rule of thumb from our projects: if you cannot name three concrete problems from the list above, keep the Inspector as your container.
Layer 3: ECS and DOTS, Only for Scale
ECS stores data in tightly packed components and runs systems over all entities that have a given set of components. Combined with the Burst compiler and the C# Job System, it lets Unity simulate far more objects per frame than GameObjects with one MonoBehaviour each. As of November 2026, Unity's ECS packages are core packages developed in line with Unity 6 releases (Unity's June 2026 ECS status post for Unity 6.6), and Unity is working on unifying Entities and GameObject workflows, for example with a shared EntityId type.
A minimal system that moves every entity with a speed component:
using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;
public struct MoveSpeed : IComponentData
{
public float Value;
}
[BurstCompile]
public partial struct MoveForwardSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float dt = SystemAPI.Time.DeltaTime;
foreach (var (transform, speed) in
SystemAPI.Query<RefRW<LocalTransform>, RefRO<MoveSpeed>>())
{
transform.ValueRW.Position +=
transform.ValueRO.Forward() * speed.ValueRO.Value * dt;
}
}
}It reads simply, but the full workflow is different from GameObjects: authoring components and bakers convert scene data into entities, subscenes hold the converted data, structural changes go through command buffers, and not every Unity feature works natively with entities. Check the Entities manual for your exact Unity version before you commit.
When ECS Is Worth It
- Yes: thousands of similar objects that update every frame. Bullet-hell projectiles, RTS units, crowds, swarms, large simulations.
- Yes, partially: one hot system in ECS, everything else on GameObjects. This hybrid is where most teams should start.
- No: a story game, a puzzle game, a platformer, UI-heavy games, or anything with a few hundred active objects. GameObjects with sensible performance habits (pooling, no per-frame allocations, simple colliders) will hit the frame budget with far less code.
- No: because it sounds faster. Profile first. If the Profiler does not show per-object update cost as the bottleneck, ECS will not fix your frame rate.
How to Choose a Unity Architecture: A Decision Checklist
- Start every project on layer 1: thin MonoBehaviours, ScriptableObjects for data, plain C# classes for rules.
- Write tests for the plain C# rules from the first week.
- Count your singletons and global lookups every month. When they start causing initialisation-order bugs or make tests painful, add VContainer (or keep Zenject if the team already uses it).
- Profile on the target device. Only when per-object simulation of thousands of entities is the measured bottleneck, move that one system to ECS.
- Write each decision down with its reason, so the next person (or agent) does not undo it.
If you need X, pick Y:
- Designers tune numbers without code: ScriptableObjects.
- Two systems must react to one event without knowing each other: a C# event on a service, or a ScriptableObject event channel for a few global events.
- Many services with lifetimes, testable without a scene: VContainer.
- An existing Zenject codebase: stay on Zenject or Extenject; a migration rarely pays back.
- Ten thousand moving things at 60 FPS: ECS with Burst for that system only.
Architecture an AI Agent Can Read and Test
In our experience, the architecture that works best with AI coding agents is the same one that works best for a new human on the team: explicit, boring and covered by tests. An agent edits a project by reading files. Every indirection (a hidden event channel, an interface with one implementation, a registration in a scope three folders away) is something it must discover before it can change code safely, and something it can miss.
What we recommend:
- Keep rules in plain C# classes, so the agent can change them and prove the change with an EditMode test.
- Prefer serialized references and constructor injection over static access and string lookups; both show dependencies in the file itself.
- Keep one composition root per scene (the scene itself on layer 1, one LifetimeScope on layer 2).
- Name ScriptableObject assets and folders consistently, so a query for "all enemy definitions" has an obvious answer.
- Record the architecture decisions in the project, for example in a Knowledge Base the agent reads in every chat (ai-game.dev/blog/game-project-knowledge-base-for-ai).
A test for the Health rules above runs in the Unity Test Framework without opening a scene. Put the gameplay code in its own assembly definition and reference it from the EditMode test assembly, so the test can see the Health class:
using NUnit.Framework;
public class HealthTests
{
[Test]
public void LethalHitReturnsTrueOnce()
{
var health = new Health(10);
Assert.IsFalse(health.Apply(4));
Assert.IsTrue(health.Apply(6));
Assert.IsFalse(health.Apply(5)); // already dead
Assert.AreEqual(0, health.Current);
}
}Where AI Game Developer Helps
AI Game Developer connects agents such as Claude Code to the live Unity Editor (ai-game.dev/engines/unity). That makes the testable architecture above pay off directly: the agent can create a ScriptableObject definition, inspect the scene's GameObjects and components through RQL queries (ai-game.dev/docs/rql), and run your EditMode tests through the tests-run tool to check its own change before you review it. It can also write a short C# snippet and run it immediately inside the editor, for example to list every MonoBehaviour that still calls FindObjectOfType before you introduce a container.
The setup takes a few minutes and is described step by step in ai-game.dev/blog/claude-code-unity-tutorial; Unity-specific advice is collected at ai-game.dev/docs/best-practices/unity. Start simple, add layers when the problem is real, and keep the tests green. Download the app at ai-game.dev/download.

