System
An object that affects multiple entities in every update of a RealityKit scene.
Declaration
protocol SystemMentioned in
Overview
In RealityKit’s Entity Component System (ECS), a system represents continuous behavior that affects multiple entities in the scene. Use systems to implement any behavior or logic that updates entities every scene update, such as different types of objects or characters. For example, a physics simulation system calculates and applies the affect of gravity, forces, and collisions for all entities. A system calls the update(context:) method as often as the updatingSystemWhen parameter of entities(matching:updatingSystemWhen:) defines.
Systems often work with components. You might, for example, create a system that calculates the hunger levels for entities in a game capable of feeling hunger. To identify which entities experience hunger, use a component that stores hunger-related state data and add it to the selected entities. The hunger system then iterates through all entities that contain a hunger component and updates their state based on relevant factors, such as when the entity last ate or how much energy it expends.
A complex game or experience may consist of many systems which need to be executed in a specific order. The dependencies property defines when the update method for each system is called each frame. Update order is defined between system types and not between individual system instances.
Systems and their dependencies form a directed acyclic graph (DAG). Custom systems are executed in dependency order. Systems without dependencies are updated in the order they were registered. If there are conflicting dependencies or cycles, then RealityKit ignores some conflicting dependencies and logs a warning. Each system instance is only run once per simulation step.
Properties of a system are never serialized to a file or synced over the network. Therefore, store data on entities using components, rather than as part of the system.
For more information, see Implementing systems for entities in a scene.