Streamlining Code Structure for Composite Fields

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 :slight_smile:

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

[CompositeGroup(0)]
[GhostField] int field1;
[CompositeGroup(0)]
[GhostField] int field Y
[CompositeGroup(0)]
[GhostField] int field Z;;

[GhostField(composite, compositeGroup=0)] int field2;
[GhostField(composite, compositeGroup=0)][int field3;

But yes, need some design

3 Likes

I’ve made a previous request like this a few months back:

At the current moment I’ve taken the advice in that thread to make my own custom code-generated serializers which works for one-off components but very tedious for multiple.

I’m happy to see some attributes being brainstormed to make the process automated.