Search Unity

Behaviour vs System

Discussion in 'Project Tiny' started by Maras, Dec 7, 2018.

  1. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    126
    Hi.
    I am ECS noob, so might be a stupid question.

    What is the benefit of using System over Behaviour? From the tutorial it seems that I could create a Behaviour instead of system and have a bit clearer code and architecture - at least from my point of view. Can I simply use Behaviours everywhere?


    BehaviourVsSystem.png


    SpawnSystem vs SpawnBehaviour might not be the best example since the forEach query is quite simple. Used just to illustrate what I mean.

    Thank you!
     
  2. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    118
    No problem. Great question! ECS noobs are who we want playing with the package!

    The benefit of using a System over a Behaviour is that you have full customization over your loop. A Behaviour comes with a small performance overhead. For small projects, this is not a problem. For developers that really need to squeeze in optimization, Systems are the way to go.

    The Behaviour is a wrapper around a System we designed to help users adapt to ECS. Behaviours end up being converted into systems at the end of the day. It was designed to feel like Monobehaviours however we did not want give users the wrong idea that they were in an OOP environment.

    I would also like to add "However, since behaviours come with implicit scheduling, you can't schedule behaviours against individual systems or fences.".

    More details can be found here: https://docs.unity3d.com/Packages/com.unity.tiny@0.13/manual/scripting.html

    Any other ECS related feedback would be greatly appreciated.
     
  3. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    126
    Thank you for this great answer.

    So can we say that if I can wrap my head around a System for specific problem, I should use it over Behaviour?
     
  4. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    118
    Yes, that would increase your skills in overall ECS. There is that trade-off of ease of readability, initial understanding, and initial write-up of a piece of code. However, ECS can be really rewarding when a user starts getting used to the basic building blocks of the architecture. You will end up reaping the benefits of performance sooner this way.

    Soon you will dive into more advanced techniques like adjusting when systems are run with system scheduling and manipulating data with the ECB (EntityCommandBuffer). This allows for the creator to really nitpick exactly what happens with code and data in a game. You will reach "performance by default" easily but can actually go much further than that.

    This architecture knowledge applies to big Unity ECS as well so not all is lost if you become an expert with the Tiny package (even in typescript).
     
    Maras likes this.
  5. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    It also looks like Systems don't have an Enable/Disable . . . so we can't do one time initialization things like setting up button callbacks, BUT behaviors can.
     
  6. MBest_Unity

    MBest_Unity

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    18
    Yes behaviours are there to make your like easier. Under the hood, they are translated into systems and a bit less efficient but often the ease of use is worrh it. We will continue to expore ways to do more abstractions like this.
     
unityunity