Building Immersive Applications with ECS-based Proprietary Engine
Most immersive applications are currently run by traditional object-oriented game engines that are not ideal for immersive purposes. It did suffice for some time when the virtual worlds were simpler, but as the character, quality and complexity of the virtual content changes, the foundation — the engine — that runs and renders virtual scenes in real time needs to be upgraded as well.
At OWNverse, we decided that to ensure that our platform and all products are stable and future-proof, it is necessary to build our own proprietary engine to be able to control, adjust and upgrade the components at any point we deem necessary.
In this article we will talk about the Entity Component System architecture for engines, and discuss why this was our choice and how this technology benefits our platform.
What is an Entity Component System?
As said, our XR engine’s primary architectural feature is its utilization of an Entity Component System (ECS) paradigm. An ECS divides the engine’s data and logic into three functional segments: entities, components, and systems.
- Entities represent game objects; they are identification tags to which components may be tied to.
- Components are self-contained pieces of reusable data that represent different aspects of an entity like physics properties, visual characteristics and audio data.
- Systems are independent pieces of logic that operate on entities containing requisite component types.
The ECS brings three primary advantages to an XR engine:
- Systems can manipulate batches of similar entities, which enables a very efficient code.
- Adding novel entities imparts negligible performance impact since systems run independently of entity counts.
- Components and systems can be developed independently and unified in various manners, conferring modularity.
This is the basis for a high-performance, scalable and extensible platform for constructing anything from basic VR demonstrations to complex AR applications.
ECS Architecture Overview
The ECS architecture partitions the engine’s data and processing into three distinct but interrelated constructs. Components encapsulate discrete data pertaining to an entity’s attributes. Entities exist as collections of components, acting as containers that group associated components together. Systems delineate discrete processing tasks that operate on entities containing specific components.
This compositional design has several benefits due to its loose coupling of elements. Since components enclose data within well-defined interfaces, they can be developed and modified independently of one another and of the entities that utilize them. Similarly, systems can be developed and altered independently as they only rely on the published interfaces of the components they utilize. This independence and encapsulation brings a lot of flexibility and reusability, and allows for evolutionary design because changes to one part of the architecture do not require invasive changes to other parts. This is why ECS is highly scalable and the modules extensible, which benefits the performance and evolvability of the engine over time.
Core Components
The material building blocks that entities are composed of are formed by fundamental core components:
- Transform components contain an entity’s positional data in 3D space as well as its rotation and scaling factors.
- Visual components describe an entity’s graphical representation encompassing properties like meshes, materials, and shaders.
- Audio components specify audio sources and effects linked to entities.
- Physics components govern an entity’s physical properties and interactions.
- Input components link entities to user input devices to enable interactivity.
- Networking components enable entities to synchronize and communicate over a network. UI components allow entities to host user interface elements.
- Script components attach executable code to entities, empowering developers to extend the engine’s functionality.
Together, they furnish the basic ingredients for constructing the virtual worlds and assets that comprise immersive applications in the ECS-based engine.
Building a Basic Scene
To build a scene within the ECS architecture comprises a few procedures in a sequence: First, developers create entities to represent the game objects in the scene — this is done by assigning an ID value to define each unique entity. Once entities exist, relevant components are appended to them to imbue the entities with data and functionality. Said entities acquire attributes by attaching sets of interrelated components that govern aspects like transform, visuals, audio, physics and more. Then, systems must be registered within the engine to operate on the existing entities and components. Systems are registered based on the component types they utilize, allowing the engine to identify which systems must process which entities. Finally, during the engine’s update loop, all active systems are executed, each processing the group of entities they are designed to operate on. This drives the behavior and simulation of the entire scene based on the interplay of the data-driven components and the processing systems.
Optimizing Performance with ECS — Advanced Techniques
Tied to our previous article about animation optimization (link), even on the engine level we can employ optimization techniques to boost the performance. What we can do:
- Entity updates can be optimized by processing entities in batches according to their most frequently accessed components, ensuring systems spend more time performing calculations and less time selecting entities.
- Managing component dependencies allows systems to only update dependent entities when relevant data changes, avoiding unnecessary processing. Dependency management can be then achieved through subscribers, triggers or property change notifications.
- Batching component data involves collecting multiple component updates into larger batches that systems then process all at once, reducing per-entity overhead. Batching is most suitable for components that are frequently modified but utilized by fewer systems.
- Entity pooling uses object pools to reuse entities that have been “destroyed” rather than allocating new memory for each entity created. Pooling entities reduces the cost of frequent entity creation and destruction, improving performance of scenes with high entity throughput.
Migrating from Other Engines
What happens when we decide to migrate content from other game engines into the ECS architecture? It can involve mapping components from those engines to analogous components within this engine. For example, data from Unity’s Transform, MeshRenderer and AudioSource components may map to this engine’s Transform, Visual and Audio components respectively. Similarly, Unreal Blueprint nodes can often be ported by mapping to corresponding Script components within this engine.
However, direct 1:1 mapping is not always possible due to differences in how engines implement certain features. We must sometimes refactor code, modify asset formats and rework content to align with this engine’s paradigms. For complex content, it is best to use a hybrid approach of porting some aspects while recreating others from scratch.
Engineers therefore have several alternatives: They can choose to port portions of content to accelerate initial development while recreating specialized systems and features natively. Or they may opt to recreate entire projects from the ground up to ensure full alignment and optimal performance within this engine’s ECS architecture. The appropriate migration strategy depends on each project’s unique requirements, balance of ported vs native content and performance targets.
Performance Analysis
Ensuring high performance to run immersive applications needs a thorough analysis of the ECS architecture’s performance characteristics. The engine provides several profiling and debugging tools to aid in performance analysis.
- Profiling tools measure the execution time of systems and components to identify bottlenecks. They generate performance statistics that reveal where the engine is spending the most time, allowing engineers to prioritize optimization efforts.
- Debugging tools help locate specific issues, such as memory leaks or stalled threads, that impede performance. Engineers can toggle performance visualization modes to inspect component data flow and system execution in real time.
Once issues are identified, performance can be improved by optimizing systems and components. Engineers may modify how systems process entities, batch component data, and structure system updates to maximize efficiency. Component designs can be refined to reduce memory footprint and minimize CPU time. Through this process of profiling, debugging, optimizing and re-profiling, the performance of immersive applications improves. The ability to closely analyze every facet of performance enables maximizing the efficiency and responsiveness of the applications.
Next Steps with the OWNverse Enterprise 2.0
The ECS architecture makes developing high-performance immersive applications possible. It has some limitations, such as loose coupling enabling flexibility and scalability resulting in complex change propagation or strict component encapsulation hampering reuse in slightly different contexts, but overall it definitely benefits the cause. The future lies in data-driven, system-oriented paradigms.
In regard to the OWNverse Enterprise 2.0, it is OWNverse’s flagship product. It is an XR engine designed to specifically enable the creation of immersive spaces, which can be used for a wide range of applications. What sets this engine apart from others like Unity and Playcanvas is its ability to run seamlessly on VR headsets without any additional setup or configuration. This is ideal for companies looking to create XR experiences for their non-tech-savvy customers or employees.
Our engine was initially developed to power the OWNverse platform, but its versatility has since made it a standalone product. This means that the OWNverse Enterprise 2.0 is available to companies building XR, especially virtual commerce space or educational XR requiring high-quality simulations.
Moving forward, the ECS engine’s roadmap in general outlines plans for future versions that will further improve the development experience, which will likely include:
- enhanced visual scripting
- integration with modern 3D toolchains
- streaming networking
- expanded physics
- AI systems
Over time, the engine aims to absorb the lessons of ECS and continue evolving to meet the full range of needs for complex immersive applications, whose standard will be continuously increasing.
Read full OWNverse Enterprise 2.0 documentation
—
Explore OWNverse and join us on Linkedin, Discord & Twitter!