O3DE Gems & Modular Architecture

🧩 O3DE Gems & Modular Architecture

In O3DE, Gems are the fundamental unit of modularity. Every feature — the renderer, physics engine, input system, even your game code — is packaged as a Gem. Think of them as self-contained packages that can declare dependencies on other Gems.


🔄 What Is a Gem?

A Gem is a directory containing any combination of:

MyGem/
├── Code/
│   ├── Include/MyGem/          # Public headers
│   ├── Source/                  # Implementation
│   │   ├── MyGemModule.cpp     # AZ::Module registration
│   │   ├── MyComponent.cpp     # Your game components
│   │   └── MyComponent.h
│   └── CMakeLists.txt          # Build targets
├── Assets/                     # Runtime assets
├── Editor/                     # Editor-only assets
├── Registry/
│   └── gem.json                # Gem metadata & dependencies
└── CMakeLists.txt              # Root CMake

📦 Core vs Optional Gems

O3DE ships with 100+ Gems. Some are essential (engine won't function without them), others are optional features you activate per-project.

Essential Core Gems

Gem Purpose
AzCore Memory, math, serialization, EBus, RTTI
AzFramework Application framework, asset system, network
Atom Multi-render pipeline (the whole renderer)
AzToolsFramework Editor tools and UI

Common Feature Gems

Gem Purpose
PhysX NVIDIA PhysX 5 rigid bodies, joints, raycasting
ScriptCanvas Visual scripting (Blueprint-like)
LmbrCentral Core gameplay components (shapes, spawners, tags)
StartingPointInput Input binding system
Multiplayer Server-authoritative networking
EMotionFX Skeletal animation, blend trees, state machines
Terrain Heightmap terrain system
Vegetation Procedural vegetation placement
NvCloth NVIDIA cloth simulation
WhiteBox In-editor mesh prototyping tool
Tip

You can list all available Gems with o3de register --list-gems. Only activate what you need — each Gem adds to compile time.


🛠️ Creating a Custom Gem

Use the O3DE CLI to scaffold a new Gem:

# Create a Gem in an external directory
o3de create-gem --gem-path C:/MyGems/WeaponSystem

# Create a Gem inside your project
o3de create-gem --gem-path MyProject/Gem/WeaponSystem

# Register an external Gem so the engine can find it
o3de register --gem-path C:/MyGems/WeaponSystem

After creation, activate it in your project:

o3de enable-gem --gem-name WeaponSystem --project-path MyProject

Or manually edit project.json:

{
    "gem_names": [
        "Atom",
        "PhysX",
        "ScriptCanvas",
        "WeaponSystem"
    ]
}

🧱 gem.json — Gem Metadata

Every Gem has a Registry/gem.json declaring its identity and dependencies:

{
    "gem_name": "WeaponSystem",
    "version": "1.0.0",
    "display_name": "Weapon System",
    "summary": "Hitscan and projectile weapon framework",
    "license": "Apache-2.0",
    "dependencies": [
        {
            "gem_name": "PhysX",
            "version_constraints": [">=1.0.0"]
        },
        {
            "gem_name": "StartingPointInput"
        }
    ],
    "compatible_engines": ["o3de>=2.0.0"]
}
Note

Dependencies are resolved at configure time (CMake). If you activate a Gem that depends on PhysX, and PhysX isn't active, the build will error with a clear message telling you what's missing.


📐 AZ::Module — Registering Your Gem

Every Gem's C++ code must register itself through an AZ::Module subclass. This is how O3DE discovers your Components at startup.

// WeaponSystemModule.cpp
#include <AzCore/Module/Module.h>
#include "WeaponComponent.h"
#include "ProjectileComponent.h"

class WeaponSystemModule : public AZ::Module
{
public:
    AZ_RTTI(WeaponSystemModule, "{GUID-HERE}", AZ::Module);

    WeaponSystemModule()
    {
        // Register all components this Gem provides
        m_descriptors.insert(m_descriptors.end(), {
            WeaponComponent::CreateDescriptor(),
            ProjectileComponent::CreateDescriptor(),
        });
    }
};

// Macro that tells O3DE "this is a loadable module"
AZ_DECLARE_MODULE_CLASS(Gem_WeaponSystem, WeaponSystemModule)

🔧 AZ::Component — Building a Component

Components are the building blocks attached to Entities. Every Component follows the same pattern:

#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>

class WeaponComponent
    : public AZ::Component
    , public AZ::TickBus::Handler       // Opt into per-frame ticking
{
public:
    AZ_COMPONENT(WeaponComponent, "{GUID-HERE}");

    // Required: declare serialized properties
    static void ReflectReflectContext* context;

    // Lifecycle
    void Init() override {}
    void Activate() override
    {
        AZ::TickBus::Handler::BusConnect();  // Start ticking
    }
    void Deactivate() override
    {
        AZ::TickBus::Handler::BusDisconnect();
    }

    // Per-frame update (like Unreal's Tick or Godot's _process)
    void OnTick(float deltaTime, AZ::ScriptTimePoint time) override
    {
        m_cooldownTimer -= deltaTime;
    }

private:
    float m_fireRate = 0.1f;      // Serialized property
    float m_cooldownTimer = 0.0f;
    int m_maxAmmo = 30;
};

Reflecting Properties (Serialization + Editor UI)

void WeaponComponent::ReflectReflectContext* context
{
    if (auto* serialize = azrtti_cast<AZ::SerializeContext*>(context))
    {
        serialize->Class<WeaponComponent, AZ::Component>()
            ->Version(1)
            ->Field("FireRate", &WeaponComponent::m_fireRate)
            ->Field("MaxAmmo", &WeaponComponent::m_maxAmmo);
    }

    if (auto* edit = azrtti_cast<AZ::EditContext*>(context))
    {
        edit->Class<WeaponComponent>("Weapon", "Hitscan weapon component")
            ->ClassElementEditorData, ""
                ->AttributeCategory, "Gameplay"
                ->AttributeIcon, "Icons/Weapon.svg"
            ->DataElement(AZ::Edit::UIHandlers::Default, 
                &WeaponComponent::m_fireRate, "Fire Rate", 
                "Seconds between shots")
            ->DataElement(AZ::Edit::UIHandlers::Default,
                &WeaponComponent::m_maxAmmo, "Max Ammo",
                "Magazine capacity");
    }
}
Tip

The Reflect system is how O3DE generates the Entity Inspector UI automatically. You define your data once — it gets serialized to disk, displayed in the editor, and exposed to Script Canvas, all from this one function.


🆚 Comparison: Gems vs Unreal Plugins vs Godot GDExtensions

Feature O3DE Gems Unreal Plugins Godot GDExtensions
Scope Can contain everything (code + assets + config) Primarily code + assets Primarily native code
Engine features as plugins ✅ Yes (even renderer is a Gem) ⚠️ Partially (some features modular) ❌ Core is monolithic
CLI tooling o3de create-gem No CLI (template wizard) scons build system
Hot-reload ❌ Requires rebuild ⚠️ Limited hot-reload ✅ Better hot-reload
Dependency system gem.json with version constraints .uplugin dependencies gdextension file
Scripting bridge Script Canvas + Lua + C++ Blueprints + C++ GDScript + C++
Build system CMake UBT (Unreal Build Tool) SCons / CMake

📁 Project Structure with Multiple Gems

A typical O3DE project references both engine Gems and custom Gems:

MyProject/
├── Gem/
│   ├── MyGameplay/      # Your core game Gem
│   ├── WeaponSystem/    # Weapon logic Gem
│   └── AIBehaviors/     # AI system Gem
├── Assets/              # Project-level shared assets
├── Levels/              # Level prefabs
├── project.json         # Active Gems list
├── CMakeLists.txt       # Root build config
└── user/                # Local user settings (not committed)
Warning

O3DE's CMake-based build can be slow for initial configuration. A full engine + project configure can take several minutes. Subsequent rebuilds are incremental and faster. Consider using Incredibuild or FastBuild for distributed compilation on teams.