New Unity ECS Coding!?!


#1

Hi All,

I just heard that Unity 2018 has a whole new coding style called the Entity Component System and it’s a radically different system than the GameObject->Component system that I/we have used up to now. Now, I am no master of the current system and have trouble with the current one, sometimes lots of trouble, but, this new system has warped my mind after watching a very small introductory video.

So, I would like to know is @ben or @Rob or anyone on the GameDev team going to be doing a course - either a introductory and longer course on this new system and/or what they are calling the Hybrid system using elements of ECS and the older component model?.

To quote Garth from the movie, “Wayne and Garth”:
weFearChange


#2

Hey Vaughan,

Firstly…

With that out of the way…

This is a change which isn’t going to happen over night. The hybrid system approach is being rolled out so that people can start using the ECS approach early and, importantly, provide feedback to Unity.

If you consider other changes which have been made to Unity in the past, it takes quite a while before something which is deprecated becomes obsolete, as such, I would fully expect the existing model to be supported for some time. Additionally, if you were to ever look at ECS and decide it wasn’t for you, you could still use an older version of Unity for sometime to come before you were forced to make that next step.

Adapting to the new model might not seem straight forward initially, but Unity tend to focus on keeping their product easy to use in order for people to get the most out of it.

With regards to GameDev.tv’s / @Ben’s plans are I cannot really say. I know that at the moment they are going back through the original Unity course and making it Unity 2018 friendly but I don’t believe this is taking the ECS model in to account at all at this stage, simply updating their product to work with the newer versions of Unity.

We could make some assumptions though, if this is being done to modernise the course content, it stands to reason that at some point it will need modernising again, as, even if a separate introductory course was created for Unity, at some point the original course, the 3D course and the RPG are all going to be out of date.

Clearly this wouldn’t be for a significant amount of time, but I think it stands to reason that the team would want to provide their students with updated content/courses so I’m fairly certain it will be covered in due course.

It would probably also be fair to assume that, due to the amount of time it takes to produce the courses, perhaps creating a course around the hybrid system might not be a worthy investment of time, as I suspect Unity would be updating this at a rate which is faster than that which GameDev.tv could update the course content for. I would imagine that the dust would need to settle so to speak before it made sense to invest the time in producing a course. At the same time, if you want to be cutting edge/leading the way, sometimes you have to take that hit and be ready to make more rapid updates.

I fully appreciate where you are coming from with regards to change but lets face it, you can’t stop it, everything is changing around us every day, so all we can do is learn to accept it and keep moving forwards - which I have every confidence you will be able to do with these changes, just as you have done so with the previous API changes for example from the original course material to the more recent versions of Unity.

The link below links to lots of useful information, but as a good overview, try the first four links;

  • ECS principles
  • Is ECS for you?
  • ECS concepts
  • How ECS works

Hope this helps :slight_smile:


See also;


#3

Further to my earlier reply, I have extracted one of the ECS samples from GitHub and put it into a .unitypackage so that you can import it and take a look, without too much clutter, but you do need to take a few steps which I’ve tried to simplify below.

Download the RotatingCubes.zip file, extract the RotatingCubes.unitypackage and then follow the steps below.

RotatingCubes.zip (20.1 KB)


  • create a new Unity project using 2018.1.0+
  • File/Exit to close Unity
  • browse to the project’s /Packages directory and open the manifest.json file with a text editor
  • replace the existing text with the following;
    {
        "dependencies": {
            "com.unity.entities": "0.0.12-preview.5"
        }, 
        "registry": "https://packages.unity.com", 
       "testables": [
            "com.unity.collections", 
            "com.unity.entities", 
            "com.unity.jobs"
        ]
    }
    
  • save the file
  • re-open the project within Unity
  • set the Scripting Runtime Version to .Net 4.x Equivalent (Build Settings / Player Settings / Other Settings)
    image
    changing this setting will require you to restart Unity
  • after Unity restarts and your project opens, import the RotatingCubes.unitypackage (Assets / Import Package / Custom Package)
  • open the RotationExample scene from within Assets/Scenes
  • click the Play button

You should see a circle of cubes with a sphere moving in a circular motion through each cubes, causing them to rotate for a short while.

  • click the Play button again to stop the game

Now take a look at the prefab, the two entities (gameobjects) in the Hierarchy and their associated components/scripts.


#4

Did you see the amount of cs files needed to just rotate the cubes/sphere - 13 files. This scares me, this scares me a lot.

I’ll do that in the next couple of days - I need a good lie down after seeing this :rofl:.

Just to be clear, what i was thinking was not a complete overhaul of the Unity courses to be compatible with ECS, they are pretty much fine for the foreseeable future, but, at some point there is going to be a need to have a course in ECS just to remain current and I would rather it come from GameDev/Udemy rather than some other format, books or heaven forbid trying to learn through websites like Brackeys - horrible forums to ask questions or on YouTube and the Unity learning system which is pretty hopeless as well. Half the tuts they have don’t work on Unity 5.

Thanks for the links, I will check them out.

Regards,
Vaughan.


#5

Did you see the amount of cs files needed to just rotate the cubes/sphere - 13 files. This scares me, this scares me a lot.

If you look at the full samples project, you will see that a lot of these are re-used, the entities anyway, the namespace samples.common is the clue here. :slight_smile:

Nothing to prevent that from happening now to be honest, the re-use, but because behaviour and data is typically mixed together this tends to happen less.

If the team does put a separate course together it may not have a lot of longevity. Much in the way that there were rumblings with regards to the issues caused by API changes between the old course and newer versions of Unity, whilst an intro to ECS might get a few people up and running, at that point I would imagine ECS to be a fully released part of Unity, if that is the case, then the current way of doing things is now old, and having courses which teach people how to do things the old way is not likely to attract a lot of students, especially if their only progress path is to then buy another course.

“Oh, so what, now I have to buy another course because this is the current way of doing it :angry:

Up to this point, with only API changes, patches could be applied, or documents created to give explanations of resolving the changes.

If there was a small course I think it would have to focus on the hybrid approach, personally, I don’t see the value in that, that would be worse than teaching someone the old way in my opinion, as then they would have to learn another way again once the hybrid was no longer available. Maybe not a big issue for the games covered in the course, but anyone wanting to make something considerably larger would not be very amused I’m sure.

The hybrid approach does offer a bit of a half-way-house though, which means people can start to get the hang of changing things/working in a different way, and for some, perhaps that is an easier first step.


#6

ecs examples

both hybrid and pure ecs


#7

unity ecs physics | movement and adding force to rigidbody