Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Streamlining Code Structure for Composite Fields

Discussion in 'NetCode for ECS' started by Opeth001, Nov 22, 2023.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,112
    Hello Unity Team,

    I wanted to share a problem I've faced multiple times that's affecting how I organize my code. Sometimes, we have "ghost components" with fields that always change together. To save bandwidth, we end up combining these fields into a new model and using it as a composite, even though it can sometimes compromise the context.
    Another common case is when a Component or Buffer Element has all its fields commonly changing together. This leads us to create another model just to hold these fields, making the code less neat and resulting in a bunch of models that only serve this specific purpose.
    I'd really appreciate it if we could find a less restricting solution to mark different fields as composite without having to refactor the full models structures for it.

    Thanks :)
     
    Last edited: Nov 22, 2023
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    Understood and agreed. The easiest would probably be to markup the grouping with an attribute or extending the GhostField to contains a composite index or group. Like

    Code (csharp):
    1.  
    2. [CompositeGroup(0)]
    3. [GhostField] int field1;
    4. [CompositeGroup(0)]
    5. [GhostField] int field Y
    6. [CompositeGroup(0)]
    7. [GhostField] int field Z;;
    8.  
    9. [GhostField(composite, compositeGroup=0)] int field2;
    10. [GhostField(composite, compositeGroup=0)][int field3;
    11.  
    But yes, need some design
     
    FaithlessOne, Richay and Opeth001 like this.
  3. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    304