Search Unity

alternative to shared component with entity values

Discussion in 'Entity Component System' started by Mordus, Oct 25, 2019.

  1. Mordus

    Mordus

    Joined:
    Jun 18, 2015
    Posts:
    174
    so apparently it's not allowed to do that. "EntityCommandBuffer.AddSharedComponentData does not support shared components with Entity fields.".

    The use case is that units are divided into teams.
    They're assigned their team when they're spawned and it never changes until they're destroyed.
    There are many places where i need to be able to easily filter and iterate units by team.

    Feels like what SCD is made for but teams are entities and i can't add an SCD that contains the team entity they belong to.
     
    Last edited: Oct 25, 2019
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    Share some code. ISCD's mit Entitys in them are allowed.
     
  3. Mordus

    Mordus

    Joined:
    Jun 18, 2015
    Posts:
    174
    i found my mistake. You can't add them with command buffers (PostUpdateCommands), they have to be added with EntityManager. Not sure why PostUpdateCommands doesn't allow it while EntityManager does, but it works at least.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I feel like teams being an integer makes more sense than an Entity.

    -edit-

    as for your issue. it's probably something to do with command buffers do an entity replacement
     
  5. Mordus

    Mordus

    Joined:
    Jun 18, 2015
    Posts:
    174
    teams are dynamic and are created/destroyed over the course of the game. it's not the kind of teams in something like an RTS where you join a game and there's X players for the length of the game. I'm also using components and buffers on the team entity to track things like resources for the team and relationships between teams.

    I understand that the entity provided by a buffer at the time you call the function is a temporary one that's replaced when the buffer is executed. Not really sure that's a reason to entirely disable the ability to use buffers for SCDs that have entity fields.