Taming the World:
How and Why RoboEngine Uses EnTT

In DevBlog #1, we broke out of our bare Vulkan window and built a proper command center with Dear ImGui. Now we had panels to click on, a Viewport to inspect, and a pressing question: what actually lives inside this 3D world, and how do we keep track of it all?
Before the editor existed, objects were just hardcoded structs living in loose lists. That flies when you have two vases and six lights, but the moment you want to spawn objects, parent them together, inspect their guts in a UI panel, and save scenes to disk, tangled object-oriented hierarchies turn into a swamp fast.
Enter EnTT, a blazing-fast – header-only C++17 Entity / Component / System (ECS) library that now serves as the beating heart of RoboEngine’s entire scene.
Today, we’re diving into why I chose an ECS, how I smuggled it into the CMake build without any baggage, and the custom rules I built on top of it to keep the engine flying straight. For more in-depth look at foundational gameplay systems, check out Game Engine Architecture (3rd edition) by Jason Gregory and Chapter 15: Introduction to Gameplay Systems.
Why an ECS (and Why EnTT)?
An editor needs to treat every object in the world with the exact same superpowers: list it in a tree, select it, display its parts, add or remove traits on the fly, save it, and undo mistakes. An ECS fits that shape like a glove.
In an ECS, an entity is nothing more than a bare ID number. “What” an object actually is comes down entirely to which components are attached to it. Want an orbiting point light? Give an entity a PointLightComponent and an OrbitBehavior. Want it to stop orbiting? Strip off OrbitBehavior, no rigid class hierarchy changes, no refactoring, no drama.
The codebase states our golden rule right up front:
// Components are plain data. Behaviour lives in systems that iterate over them.
Components are stored in tightly packed arrays per type, and systems query them with views like registry.view<WorldTransform, MeshComponent>(). Among C++ ECS libraries, EnTT won the spot on my gear list for five standout reasons:
Zero-friction header-only setup:
- No external .lib or .dll to compile or link—just point the compiler’s include path at EnTT’s src/ folder and you’re off to the races.
Versioned, safe IDs:
- An entt::entity packs both an index and a version number. If an entity gets destroyed, its old ID immediately fails valid(), even after its memory slot gets recycled by a brand new object. That means the editor can hold onto a selection handle without ever risking a dangling pointer.
Built-in type hashes:
- entt::type_hash<T>::value() generates a stable ID for every component type, acting as the master key that links my Inspector UI and JSON scene files directly to C++ structs.
In-place sortable storage:
- EnTT lets you re-sort component arrays right in memory, a superpower our transform system uses to guarantee parents always update before their children.
Exact ID resurrection:
- Calling registry.create(hint) lets us revive a specific entity index and version, which is the exact magic trick that lets our upcoming Undo system restore a deleted object with its original ID intact.
Smuggling EnTT into the Build
Because EnTT requires zero linking, the CMake setup is all about locating its headers cleanly. If ENTT_PATH is defined in .env.cmake, the build uses that local copy. Otherwise, CMake automatically fetches a shallow clone of a pinned release at configure time:
if(DEFINED ENTT_PATH)
set(ENTT_INCLUDE "${ENTT_PATH}/src")
else()
include(FetchContent)
FetchContent_Declare(entt
GIT_REPOSITORY https://github.com/skypjack/entt.git
GIT_TAG v3.15.0
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(entt)
if(NOT entt_POPULATED)
FetchContent_Populate(entt) # Only headers needed—skip EnTT's own CMake project
endif()
set(ENTT_INCLUDE "${entt_SOURCE_DIR}/src")
endif()
target_include_directories(${PROJECT_NAME} PUBLIC ... ${ENTT_INCLUDE} ...)
Using FetchContent_Populate instead of FetchContent_MakeAvailable is a deliberate tactical move: it grabs the source files without executing EnTT’s own CMakeLists.txt, keeping its tests, options, and install targets from polluting RoboEngine’s build. (nlohmann/json, which joined the party to power our scene files, gets pulled in the exact same way.) Meanwhile, the local ENTT_PATH override makes offline builds or testing newer EnTT releases effortless.
ReScene: Guardrails Around the Registry
ReScene owns the entt::registry and exposes it openly through registry(). Rather than burying EnTT behind heavy abstractions, ReScene acts as a lightweight set of guardrails enforcing the few structural rules a raw registry doesn’t know about:
1. Every Entity Starts with a Standard Kit
Whenever createEntity spawns something new, it automatically attaches four foundational components so no system ever has to waste time checking if they exist:
const Entity entity = registry_.create();
registry_.emplace<NameComponent>(entity, name.empty()
? "Entity " + std::to_string(entt::to_entity(entity))
: name);
registry_.emplace<TransformComponent>(entity);
registry_.emplace<WorldTransform>(entity);
registry_.emplace<Hierarchy>(entity);
2. An Intrusive Linked-List Hierarchy
EnTT doesn’t ship with a built-in parent/child tree, so we built one right inside the Hierarchy component. Each node stores parent, firstChild, prevSibling, and nextSibling as plain entity IDs, forming an intrusive linked list woven across the registry. Only ReScene (setParent, destroyEntity) is allowed to touch those links so the tree never tangles.
3. Linear, Recursion-Free World Transforms
Every Hierarchy component also tracks its tree depth (0 for root entities). Whenever the tree changes, the transform system sorts the Hierarchy array by depth, then sorts both transform arrays to match that exact memory layout:
if (orderDirty)
{
registry.sort<Hierarchy>([](const Hierarchy &a, const Hierarchy &b) { return a.depth < b.depth; });
// Align the transform arrays to match so the loop walks memory linearly
registry.sort<TransformComponent, Hierarchy>();
registry.sort<WorldTransform, Hierarchy>();
orderDirty = false;
}
auto view = registry.view<const Hierarchy, const TransformComponent, WorldTransform>();
view.use<const Hierarchy>(); // Iterate in depth-sorted order
for (auto [entity, node, local, world] : view.each())
{
glm::mat4 matrix = local.mat4();
if (node.parent != NullEntity)
matrix = registry.get<const WorldTransform>(node.parent).matrix * matrix;
world.matrix = matrix;
// ...compute normal matrix...
}
Because parents are guaranteed to sit ahead of their children in memory, one single linear pass computes every world matrix in the scene with zero recursion and peak cache friendliness.
Best of all, the sort only runs when hierarchyOrderDirty_ flips true after a spawn, delete, or re-parent, never on idle frames.
4. Fixed System Execution Order
ReScene::update(dt) runs gameplay behaviors first (currently updateOrbits) and computes world transforms last, guaranteeing that the renderer always sees the exact positions calculated during the current frame.
Systems Powered by Views
Every consumer in RoboEngine asks the registry for the exact slice of data it cares about—and nothing more. Nobody needs to know how entities are stored under the hood:
| Consumer | Registry View / Source | What It Reads & Writes |
| Orbit System | TransformComponent, const OrbitBehavior | Writes updated local translation |
| Transform System | const Hierarchy, const TransformComponent, WorldTransform | Writes world and normal matrices |
| Mesh Renderer | const WorldTransform, const MeshComponent | Feeds push constants and issues draw calls |
| Point-Light System | const WorldTransform, const PointLightComponent | Populates the global UBO light array and draws billboards |
| Viewport Picking | Meshes and lights | Casts rays against triangles and light spheres |
| Serializer & Inspector | The Component Table | Drives generic save, load, and UI editing per type |
Look how clean the mesh renderer becomes when it only cares about world transforms and meshes:
auto meshes = frameInfo.scene.registry().view<const WorldTransform, const MeshComponent>();
for (auto [entity, transform, mesh] : meshes.each())
{
if (!mesh.model) { continue; }
SimplePushConstantData push{};
push.modelMatrix = transform.matrix;
push.normalMatrix = glm::mat4(transform.normal);
// ...push constants, bind, draw...
}
And our orbiting lights? A complete gameplay behavior system in roughly ten lines of code:
for (auto [entity, transform, orbit] : registry.view<TransformComponent, const OrbitBehavior>().each())
{
const float axisLength = glm::length(orbit.axis);
if (axisLength < 1e-6f || orbit.speed == 0.0f) { continue; }
const glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), orbit.speed * dt, orbit.axis / axisLength);
const glm::vec3 offset = transform.translation - orbit.center;
Notice the const qualifiers inside the views—it’s self-documenting armor that clearly declares what a system merely reads versus what it mutates.
When saving scenes to JSON, the serializer walks entities depth-first (so parents always serialize before children) and keys them using entt::to_integral(entity). On load, it spawns fresh entities and remaps file IDs to newly minted registry IDs, meaning scene files never break if the registry hands out different numbers next time.
Traps & Mobs in the Registry
Working with a data-oriented ECS comes with a few sharp edges if you aren’t paying attention. Here are the six biggest pitfalls we dodged along the way:
Component arrays shuffle on change
- EnTT appends new components to the end of packed arrays and fills deletion gaps by swapping the last element into the empty slot. Either operation breaks our parents-first sorting order, which is why createEntity, destroyEntity, setParent, and clear all flag hierarchyOrderDirty_ for the next transform pass.
Never walk links you’re actively destroying
- destroyEntity gathers an entity’s entire subtree into a std::vector before calling registry_.destroy(begin, end). Deleting as you walk firstChild and nextSibling would mean reading links off entities that have already vanished from existence.
Mind the GPU resources inside components
- A MeshComponent holds a shared_ptr<ReModel>, whose Vulkan buffers might still be actively used by frames in flight. Destroying an entity can drop the final reference and trigger buffer destruction mid-draw, so every editor path that deletes entities or swaps meshes calls vkDeviceWaitIdle first.
Keep internal plumbing out of the UI
- Hierarchy and WorldTransform are intentionally excluded from the component reflection table. The scene manages parent links and recomputes world matrices every frame, so the Inspector hides them and scene files never bloat themselves saving derived data.
Entity IDs are transient
- Scene files only record raw integer IDs to reconstruct parent-child relationships during loading; once loaded, entities take whatever IDs the registry assigns. The only place exact ID identity matters is our Undo stack, which uses registry.create(hint) to bring deleted entities back from the grave with their exact index and version.
Guard the math, not just the pointers
- Setting an entity’s scale to 0 makes its 3×3 basis matrix non-invertible. Rather than letting NaN values poison the normal matrix and turn a mesh pitch-black under lighting, the transform system gracefully retains the previous valid normal matrix.
Next Up on the Quest
With our ImGui command center wired up and EnTT cleanly organizing every entity, component, and transform in the world, we finally have all the pieces needed for true scene editing. In further DevBlogs, we’ll see how the component table powers both generic JSON serialization and a full Command-Pattern Undo/Redo system!
