Search Unity

Global data to be accessed by a system

Discussion in 'Entity Component System' started by 11tomi12, Sep 8, 2019.

  1. 11tomi12

    11tomi12

    Joined:
    Feb 25, 2016
    Posts:
    17
    I am new to ECS and am trying to convert a very simple traffic simulation to it.

    My entities are vehicles that have data for direction, navigation data and movement.
    Systems move, rotate and set a new path when hitting an intersection.

    My problem is that the data from paths and intersections is stored in lists and arrays. I don't know how I would arrange the data so that it acn be accessed to determine a new path. I tried it with a singleton but Burst doesn't allow non-readonly statics. my other idea was to create 2 new types of components, paths and intersections. I would then need a way to acces all entities of those types at once in a system. How could I do that? My idea was GetEntityQuery but couldn't get it to work.
     
  2. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    353
    To access global data (singleton's static as i understand) u can use SharedStatic. Also u can arrange your data as DynamicBuffers which accessed inside bursted job as well.
    Getting all entities through EntityQuery should work, maybe u do something wrong with parameters of GetEntityQuery().
     
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    ComponentDataFromEntity and/or BufferFromEntity are probably what you want for being able to access all entities of the types you care about in a random access manner.
     
  4. 11tomi12

    11tomi12

    Joined:
    Feb 25, 2016
    Posts:
    17
    Thank you for your help guys. I managed to make GetEntityQuerry and ToComponentDataArray work.