This page collects common usage patterns drawn from the MiniECS source and the bundledDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/raoulkdev/MiniECS/llms.txt
Use this file to discover all available pages before exploring further.
main.cpp example. Each snippet is self-contained and maps directly to the public API exposed by World, Unit, and the built-in modules. Read through them in order for a progressive introduction, or jump to the pattern most relevant to your use case.
Example 1
Basic scene with Transform and Renderer
The simplest possible MiniECS program creates aWorld, adds one Unit, attaches a couple of modules, sets an initial value, and starts the loop. This is the exact code from src/main.cpp.
Example 2
Multiple units in a scene
World holds an arbitrary number of units. Create each one with createUnit(), attach whichever modules it needs, then configure their initial state through getModule<T>(). Units that don’t share the same module set coexist without issue — only the modules actually attached to a unit are called during play().
Example 3
Always check getModule<T>() for nullptr
Unit::getModule<T>() performs a dynamic_cast over the unit’s module list and returns the first match, or nullptr if no module of type T is attached. It also prints a message to std::cerr when the module is not found. Always guard the returned pointer before dereferencing it — omitting the check will produce undefined behaviour if the module was never added.
Calling
addModule() with a ModuleType that already exists on the unit is safe — the framework detects the duplicate and prints a warning without adding a second copy. getModule<T>() will still return the original instance.Example 4
Iterating over all units in a World
World::getUnitsVector() returns a const reference to the internal std::vector<std::unique_ptr<Unit>>. Use a range-based for loop to inspect or operate on every unit without modifying the container.
Example 5
Removing units by name or index
Units can be removed from aWorld either by their string name or by their zero-based position in the units vector. Both operations destroy the unique_ptr and invoke the destructors of all modules still attached to that unit.