
Unity ECS Squad Movement Simulation
Unity ECS is a growing programming paradigm for performant code, making use of the C# Job System and Burst Compiler to create some outstanding projects. As part of my Media Specialist Practice module, I chose to use this new system to create a Squad Movement Simulation.
![]() | ![]() |
---|---|
![]() | ![]() |
This project, has been one of the most difficult projects I have yet attempted. The idea of the project was to create basic movement for a high amount of units, to try and carry on into a battle simulation for a future project. To achieve this, I looked into Unity ECS, a programming paradigm that has existed for a while, but only recently becoming popular on Unity. The idea was this could support the high amount of units I wanted, and could get them to move from one place to another, while remaining in a formation and avoiding obstacles.
This proved to be manageable at first, as early tests showed that with a little more work, the total object count could be increased from about 10,000 to 250,000 while remaining at 30 fps (cubes pictured above). However, as progress went on, areas that would be simple in Monobehaviour started to prove a challenge when using ECS. Blittable types became a quick problem, that ultiamtely played a part in the poor performance with a high object count. A blittable data type doesn't have to be converted when sent to the compiler. However, there are two different data types that are hard to create a game/simulation without that are not blittable, boolean and arrays. A quick fix was made for a boolean using a byte, and since creating the project Unity has updated entities to have boolean support. Arrays however remain non-blittable, meaning they cannot be part of an entity's component data.
To keep units in formation when, flocking was used staying to the three rules: alignment, cohesion and seperation. It took a while to get working, and isn't near 100% working. As seen, units have a tendency to start rapidly turning as they are nearing their destination. However, this is due to the flocking behaviour. The main performance decrease of the simulation is due to both my own lack of experience in ECS, and blittable types. As in Monobehaviour, a game object squad can hold a list reference to all units in it's squad, and be able to check how far other squads are, to see if any avoidance calculations need to be made. In ECS, you cannot hold a list like this. Instead, entities need to be found within a job every frame. This caused a lot of overhead when needing to find entities that are within a squad. After a week of trying to solve this, little was found and time ran out. However, with more time it could be possible to reorganise it, to allow check to be made rarely, or stored to greatly increase performance.
Even though the final result doesn't contain the high object count intended. With more time, and some changes to Unity ECS it could very much be possible soon. But even now, a lot is still possible, depending on the desired goal. Small games can easily be made with simple mechanics, and even if they aren't big games they might still run better than if created with Monobehaviour, which is brilliant for mobile games as it can reducde heat and increase battery life. Even if Unity ECS doesn't support a full game, a lot can be done that can aid one. In an earlier test of linear movement, high frames could still be achieved with thousands of units, showing it could still be great for building a background world within a game. There is a lot of potential with what could be done, but maybe at this time, not 100% ready for a full on project.