Search Unity

Systems as event handlers

Discussion in 'Entity Component System' started by JooleanLogic, Jan 17, 2019.

  1. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Outside of the memory cost and post OnCreateManager once all ComponentGroups are registered, is the ecs engine itself negatively impacted at all by the number of components/archetypes/systems or are all runtime operations O(1)? E.g. adding a component to an entity causing it to change archetypes or using ComponentDataFromEntity.
    Is there any problem in having hundreds of components/archetypes/systems?

    I was thinking of using JobComponentSystems as event handlers for my collision system like so.
    Code (CSharp):
    1. IJobProcessComponentData<CollisionInfo, BulletTag, SpaceshipTag>
    2. IJobProcessComponentData<CollisionInfo, SpaceshipTag, ExitDoorTag>
    To create a collision event handler, you just create a component system with a CollisionInfo component and the tag components of the two objects you're interested in.
    The collision system would spawn entities with the relevant components which is always just a single readonly data component and two tag components.
    I realise this is somewhat archetype/chunk heavy but it's also so easy to create event handlers like this and they're all jobified.
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    The number of systems affect the algorithm that arrange systems into player loop according to UpdateBefore/After/Group, IIRC from some early threads. And this adds up to the enter play mode time that is already slow. (after all it suffers from the same whole-assembly problem) I don't know if they had made this better by now or not.

    Edit : found https://forum.unity.com/threads/taking-forever-to-enter-playmode-solution-inside.543283/
     
  3. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Thanks 5argon. Yes I remember that post but I thought that only affected the initialisation phase when ecs registers all the systems.
    Does that before/after algorithm actually take place every frame?
    Do you know if it's just O(n) or worse?

    Apart from the obvious linear cost of extra systems, it would be good to know what operations in ecs are affected by worse than O(1) algorithms and whether Unity expects to be able to make everything post initialisation O(1) down the track.
    I already have over 60 components and 50 systems and I've barely started porting my game.
    This doesn't seem to be any kind of problem atm but I'm curious what the limits are if any.