Search Unity

Unique Component

Discussion in 'Entity Component System' started by Ziboo, Mar 21, 2018.

  1. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Hi,

    I was wondering if you will implement something to have Unique Component/ComponentData.
    For instance for a single player game, you will have only one "Player" Component living in the World.

    Right now you can only inject Arrays of components, so you always need to iterate through them, which make typing more code.

    Entitas had a "Unique" attribute if you want reference.

    Thanks
     
    Filtiarn_ likes this.
  2. RootCauseProductions

    RootCauseProductions

    Joined:
    Feb 1, 2018
    Posts:
    31
    This is not a "no" vote for this feature, but coming from the Java world, I am use to lots (OMG, lots and lots) of boilerplate. I haven't done it yet, but I plan to make snippets in Visual Studio to generate that boilerplate for me with just a few keystrokes. It shouldn't be hard to add a new Create menu option to make components and systems, but I tend to group them in a few files instead of one per file so the snippets make more sense for me.
     
  3. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    RootCauseProductions likes this.
  4. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Shared doesn't mean Unique.
    In the sample they used a SharedComponent for look of the models, it's always the same mesh, always the same material, so you can share that between entity.

    What I meant was, accessing a unique component, or maybe a shortcut to access the first entity in the array.

    Instead of having:
    Code (CSharp):
    1. struct PlayerData
    2.         {
    3.             public int Length;
    4.  
    5.             public ComponentDataArray<PlayerInput> Input;
    6.         }
    Something like:
    Code (CSharp):
    1. struct PlayerData
    2.         {
    3.             public PlayerInput Input;
    4.         }
    Assuming only one PlayerInput can be alive in the World of course