Firstly: I’m truly sorry. I’m far away behind the schedule with the AI Decision System. I have been busy with work priorities and other personal life stuff. I will be back in track with the series as soon as possible, but as long as I do not have enough time to do something cool with good practical examples, I decided to do a spin-off post about Unity’s Entity Component System.
Unity is introducing a new high performance multithreaded system, that will make it possible for your game to fully utilise the multicore processors available today without heavy programming headache. (check more information about Unity’s ECS)
The repository for this article’s sample is already available.
In order to get this ECS working with your Unity 2018.1, you will need to replace project’s manifest.json file with the following code:
This new ECS is pretty good to create awesome components for your game. :)
The struct above will define our Player Input data which will be used by our Player Input System’s Job to update horizontal and vertical values.
Breaking down Player Input System’s Job
This class represents our entire Player Input System; Firstly, the data needed to store user’s input values is defined, then we create Execute method which will be responsible to update our values. Then, we override OnUpdate method and create a new instance for our job and return its execution scheduled.
Note that when inheriting IJobProcessComponentData < PlayerInput > we get a PlayerInput reference and work with its reference when updating the values.
This system is simple and really easy to understand. Now we can move forward and have our Player Movement System to consume the data from Player Input and update its own position.
Note that for each JobComponentSystem we have to schedule and return the job in order to get it working properly.
Player Movement System
Last but not least, our Controller will be responsible to create an Player Archetype containing the needed components and be handled by an Entity Manager.