Search Unity

Question About Examples And How Systems Are Created

Discussion in 'Entity Component System' started by dkilmer, Apr 11, 2019.

  1. dkilmer

    dkilmer

    Joined:
    Jul 12, 2015
    Posts:
    6
    I'm working through the ECS Samples, and I'm struggling to understand how Systems are created. In all the examples, there's a ComponentSystem or JobComponentSystem defined in the project that seems to automatically get started up without being attached to anything, and without anything explicitly creating it. Does Unity just start up any system that happens to be defined in your project? And if that's true, why does example 06 (SpawnFromEntity) start up a HelloSpawnerSystem but none of the other Scenes do? Is there a way to know or control what is going to be created?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    First, Unity has attributes that allow a method in your codebase to be called when a certain event happens.

    Second, Unity has a method in one of their packages that uses reflection to dig through all the types of all your assemblies and by default instantiate all the systems you have defined. All of this behavior can be overriden by either a custom bootstrap or disabling automatic world creation.

    The code to look it is all Unity.Entities.Hybrid/Injection.
     
    dkilmer likes this.