Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question SharedComponent Lookup (random access) inside Job

Discussion in 'Entity Component System' started by bitMagus, Jul 22, 2023.

  1. bitMagus

    bitMagus

    Joined:
    Jul 7, 2019
    Posts:
    4
    Hello, I started playing with ECS now that 1.0 is out, so my knowledge of the API is very limited.
    Is there a way to randomly access a SharedComponent, given an entity, from a Job (more specifically an IJobEntity)?
    For ComponentData I use ComponentLookups, and for SharedComponents random access I can use the EntityManager.GetSharedComponent but I think it's not possible to pass the state.EntityManager to a job?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,976
    It is a bit messy, but a combination of EntityStorageInfoLookup and SharedComponentTypeHandle will get you there.
     
    bitMagus likes this.
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,623
    bitMagus likes this.
  4. bitMagus

    bitMagus

    Joined:
    Jul 7, 2019
    Posts:
    4
    Thanks Latios, just what I needed, works perfectly.
     
  5. bitMagus

    bitMagus

    Joined:
    Jul 7, 2019
    Posts:
    4