tutorial.mp4
This prototype is an initial exploration into ECS (Entity Component System) and DOTS (Data-Oriented Technology Stack) programming in Unity.
The goal of this project is to allow users to design a circuit and assign it to a car spawner. Spawned cars will then follow the defined circuit until they reach the end.
I chose to implement this project using Unity’s latest recommendations, as some older methods are deprecated or scheduled for deprecation. One of the key limitations of traditional Unity OOP is its reliance on a single-threaded architecture. To overcome this, I leveraged Unity's ECS (Entity Component System) and ScheduleParallel, which allows tasks to run across multiple threads for improving performance and scalability.
Left click to place a circuit on editor.
- Unity – Version 6000.2.2f1
- C# – Used for gameplay scripting
Before starting this project, I had heard about ECS and DOTS but had never actually programmed with them. The biggest challenge was shifting from traditional OOP (Object-Oriented Programming) to the ECS paradigm. Concepts like baking, subscene authoring, and systems were completely new to me, and it was difficult at first to visualize how to build a functioning system using this approach.
Much of my previous Unity experience didn’t translate directly, as ECS programming steers you away from many of the familiar UnityEngine functions and patterns. This made the learning curve quite steep.
Clone the repository:
git clone https://github.com/Vpekdas/Simple-ECS/
Then open the Sample Scene in Unity.
To create and run a circuit in the scene, follow these steps:
- Ground
- Located in the
Assets/Prefabs/folder. - Drag it into the scene. This enables raycasting, which is required for placing circuit points.
- Located in the
- LevelEditor
- Also found in the
Assets/Prefabs/folder. - Place it in the scene. It allows you to create a circuit using left-click.
- Once you're done placing the circuit, you can either remove the LevelEditor or simply disable it in the editor.
- Also found in the
- BakeScene (Subscene)
- Located found in the
Assets/Scenes/folder. - This subscene is crucial, it tells Unity to convert GameObjects into Entities.
- Be sure to check the small checkbox on the right of the BakeScene in the Hierarchy to enable editing.
- Located found in the
- CarSpawner
- Located found in the
Assets/Prefabs/folder. - Place it in the subscene. You can customize the color, speed, and spawn interval of the cars.
- Don’t forget to assign the circuit (created in the next step) to the spawner.
- Located found in the
When you have placed all of those, you need to check the little fillbox at right of BakeScene to allow editing.
- After placing the circuit points in the scene using the LevelEditor, group them all under a single parent GameObject.
- Drag this parent object into the subscene to convert it into an entity.
- Place a
CarSpawnerin the subscene and configure its parameters:CarPrefabCircuitParent: Give the parent you created previously.MoveSpeedColorPickerSpawnInterval
Warning
All these elements (Ground, Circuit, CarSpawner) must be inside the subscene to be processed correctly by Unity’s ECS/DOTS pipeline.
Repeat the process for each circuit you want to create.
Thanks to the interviewer that sent me this test ! It was very cool to program and learn.
To report issues, please create an issue here: issue tracker.
If you'd like to contribute, please follow the steps outlined in CONTRIBUTING.md.
This project is licensed under the MIT License.