Video: Entities "Tanks" Tutorial walkthrough (23 minutes)
- Randomly colored tanks move on a plane and spin their turrets.
- The tanks shoot colored projectiles which bounce on the ground and despawn after a while.
The text below describes the general idea of each step, but you're strongly encouraged to study the code and read the comments.
Introduces instantiation of rendered entities using a baked "sub scene".
In the Step 1 scene, the subscene contains a rendered cube GameObject called "Tank", which has a child sphere called "Turret", which has its own child cylinder named "Cannon". For each of these three GameObjects, baking serializes one entity with transform and rendering components. So be clear that the GameObjects of the sub scene will not be loaded at runtime: the tank you see rendered in play mode is comprised of entities, not GameObjects.
Introduces unmanaged systems (
ISystem), queries, andSystemAPI.Query.
New code files:
Scene changes:
- The
TurretAuthoringMonoBehaviour is added to the "Turret" GameObject. In baking, this will add aTurretcomponent to the turret entity.
When TurretRotationSystem updates, it applies rotation to the transform of every entity which has the Turret component (defined in "TurretAuthoring.cs").
Introduces scheduling a parallel job.
New code files:
Scene changes:
- The
TankAuthoringMonoBehaviour is added to the "Tank" GameObject. In baking, this will add aTankcomponent to the tank entity.
When TankMovementSystem updates, it moves every entity which has the Tank component (defined in "TurretAuthoring.cs") along a random curve.
Introduces aspects, entity prefabs,
EntityCommandBuffer, andIJobEntity.
New code files:
Scene changes:
- The new "CannonBall" prefab consists of a single GameObject: a sphere with the new
CannonBallAuthoringMonoBehaviour, which in baking adds aCannonBallcomponent to the entity. - The "Cannon" GameObject has a new child "SpawnPoint" GameObject. The "SpawnPoint" transform represents the point at which to spawn the cannon balls.
- The
TurretAuthoringfield "CannonBallPrefab" is set to reference the new "CannonBall" prefab, and "CannonBallSpawn" is set to reference the "SpawnPoint" GameObject. In baking, theTurretAuthoringbaker will assign the entities produced from this prefab and this GameObject to the fields of theTurretcomponent.
The TurretAspect provides a (minor) abstraction around the components of the turret entity.
When TurretShootingSystem updates, it spawns cannon ball entities at the tip of the cannon at regular intervals.
Introduces scheduling a parallel job with
IJobEntity.
New code files:
The CannonBallAspect provides a (minor) abstraction around the components of the cannon ball entities.
When CannonBallSystem updates, it applies pseudo-gravity to the cannon balls and destroys them after their speed goes below a threshold.
Introduces dynamically spawning entities at the start of the game.
New code files:
Scene changes:
- The tank has been made into a prefab.
- The
ConfigAuthoringreferences the tank prefab and specifies the number of tanks to spawn.
When TankSpawningSystem updates, it spawns multiple tanks, setting their URPMaterialPropertyBaseColor components a random color value. Because we want the system to only spawn tanks one time, the system sets its SystemState.Enabled property to false, which stops it from updating again.
Introduces enableable components (
IEnableableComponent), live conversion, and storing basic configuration data in a singleton.
New code files:
Scene changes:
- The
ConfigAuthoring"safe zone radius" value is set to 10.
When SafeZoneSystem updates, it enables the Shooting component of tanks outside the safe zone radius and disables the component of all tanks inside the radius.
Note that the white circle is only visible if gizmos are enabled:
Also note that changing the "safe zone radius" value in play mode triggers a re-bake, so the active value in game can be updated live.
Introduces input handling in a system and simple runtime coordination between ECS and GameObjects.
New code files:
Scene changes:
- The "Main Camera" GameObject (in the main scene, not the sub scene) has the new
CameraSingletonMonoBehaviour.
When CameraSystem updates, it picks a different random tank for the camera to follow if the user hits the space bar.
END OF TUTORIAL
Tanks for reading!









