Search Unity

Is TeamId a bad candidate for SharedComponentData?

Discussion in 'Entity Component System' started by LukePammant, May 14, 2019.

  1. LukePammant

    LukePammant

    Joined:
    Mar 10, 2015
    Posts:
    50
    It seems that TeamId would be a natural candidate for ISharedComponentData in order to skip chunk processing on same/opposite teams. That being said - I find myself needing to get the value of the team on a referenced entity while in a IJobFor via something like ComponentDataFromEntity<Team>(someOtherRefenencedEntity) but this is not allowed.

    Perhaps I need a 'SharedTeam:ISharedComponentData' for chunk iteration, and a 'Team:IComponentData' to access whilst in a job. Would this be frowned upon?

    Has anyone else had a similar issue? If so how do you solve it?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Originally I did something similar with 2 team components to get around this problem.

    1 SharedComponentData for grouping
    1 ComponentData for querying

    Not sure I'd recommend it though. It worked ok, but I ended up removing the SharedComponentData because apart from querying targets on different teams for AI, grouping by team actually made little sense since usually everything is just processed together (and I built a more efficient team query system using caching that didn't rely on chunks.)
     
    LukePammant likes this.
  3. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    I've used SharedComponentData for teamId too, although like tertle I've had mixed feelings on it.

    It's just a bit awkward using shared component data (have to do chunk iter, can't access in jobs). More and more I think of it as a specialist thing for doing chunk based operations and sorting rather than just something that you should use by default for common data.

    Going forward I think by default I will favour not using it for things such as teamId and can always start using it later if it turns out it gives some benefit.
     
    LukePammant likes this.
  4. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    I just worked through a similar problem and ended up using SharedComponent and IParallelFor with chunks to streamline processing:
    https://forum.unity.com/threads/sim...ata-on-another-component.670036/#post-4552492

    SCDs seem to be good at segregating data and allowing you to early out on some chunks. If you use IParellelFor, you can also access SCD data in Execute by looking at other chunks. Not sure if this is possible in IJobChunk, would like to see an example if it is.
     
    Last edited: May 17, 2019