Plugin architecture

From decentraland/unity-explorer · View interactive version

Plugin architecture is an AI agent skill from the GitHub repository decentraland/unity-explorer. Plugin and DI architecture. Use when adding or modifying plugins (IDCLWorldPlugin, IDCLGlobalPlugin), system registration, dependency injection, containers, assembly structure, or Addressables provisioning.

How to use this skill

Skill file

Plugin & Dependency Architecture

Sources


Plugin Types

IDCLWorldPlugin — Scene-Scoped

Created per scene world. Receives world-specific dependencies and injects systems into that world.

Lifecycle:

  1. InitializeAsync(TSettings, CancellationToken) — Load addressable assets, create pools
  2. InjectToWorld(ref ArchSystemsWorldBuilder, ...) — Register systems into the world
  3. Dispose() — Clean up resources

Key parameters in InjectToWorld:

IDCLGlobalPlugin — Application-Scoped

Created once for the application lifetime. Injects systems into the global world only. Same lifecycle as world plugin but with GlobalPluginArguments instead of world-specific dependencies.


Plugin Settings


Container Architecture

Dependency flow direction (critical)

Dependencies flow top-down from the composition root into containers, and then from containers into plugins. The direction is one-way.

Composition root (MainSceneLoader / Bootstrap)
       │ constructs, injects deps into
       ▼
   Containers (StaticContainer, DynamicWorldContainer, feature-scoped containers)
       │ provide deps to
       ▼
   Plugins (IDCLWorldPlugin, IDCLGlobalPlugin)
       │ register systems via
       ▼
   ECS Systems

Rules:

Decoupling without ObjectProxy

Match the situation to the recipe (full rationale in docs/architecture-overview.md § "Deferred dependencies — decoupling without ObjectProxy"):

| Situation | Fix | Existing example |

|---|---|---|

| Service trapped in a late, UI-owning container | Split services into their own container created before any consumer | FriendsServicesContainer (services) vs FriendsContainer (UI) |

| Dependency exists only when a feature flag is on | Pass T? (null = disabled) and null-check where .Configured used to be, or use a null-object | IFriendsService?; NullUserBlockingCache, NullRoomHub |

| Scene-world plugin needs comms/multiplayer services | Construct the plugin in DynamicWorldContainer.WorldPlugins, not in StaticContainer with an empty slot | AvatarAttachPlugin, SceneMaskedEmotePlugin, RealmInfoPlugin |

| Dependency is per-scene data | Add it to ECSWorldInstanceSharedDependencies, threaded from SceneFactory | IRoomHub for the media streaming room |

| Object created in a plugin's async InitializeAsync but consumed by earlier objects | Create it eagerly in a container; the plugin only attaches the UI-bound parts | NavmapCommandBus + NavmapCommandFactory.AttachUiControllers |

Symptoms of inverted flow:

StaticContainer

Created first. Produces common dependencies and world plugins.

DynamicWorldContainer

Created after StaticContainer. Holds global plugins and runtime state.

ComponentsContainer

Registers SDK component types for CRDT deserialization. Each SDK component must be registered here.


Assembly Structure

Core principles

Assembly rules for ECS Systems

ECS Systems must always use an .asmref pointing to DCL.Plugins:

{ "reference": "DCL.Plugins" }

Assembly rules for Tests

Tests use an .asmref pointing to the shared test assembly:

{ "reference": "DCL.EditMode.Tests" }

For PlayMode tests use DCL.PlayMode.Tests instead.

Naming convention for `.asmdef` and `.asmref`

Examples from the project:

| File | Location |

|------|----------|

| DCL.Multiplayer.Movement.Systems.asmref | Multiplayer/Movement/Systems/ |

| DCL.Landscape.Systems.asmref | Landscape/Systems/ |

| DCL.Input.Systems.asmref | Input/Systems/ |

Feature folder structure

Assets/DCL/<Feature>/
├── Components/
├── Systems/
│   ├── DCL.<Feature>.Systems.asmref  ← { "reference": "DCL.Plugins" }
│   ├── <Feature>Plugin.cs            ← plugin lives WITH the systems it injects
│   ├── <Feature>LifecycleSystem.cs
│   └── <Feature>ApplyPropertiesSystem.cs
├── Tests/
│   └── EditMode/
│       ├── <Feature>SystemShould.cs
│       └── EditMode.asmref               ← { "reference": "DCL.EditMode.Tests" }

Plugin file placement


Detailed Reference

For detailed code examples, see reference.md.


Cross-References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.