Support for Multiple Write Groups

Hey all!

Just did some testing and it looks like a single component can’t be part of multiple write groups - works fine with either one or the other, just not both at the same time.

For context I’d like to create an unknown number of components that could override how I write to other components. For example, I’d want the ability to override writing to Translation and Rotation (individually or both at the same time)

// This only overrides translation, not rotation
[WriteGroup(typeof(Translation))]
[WriteGroup(typeof(Rotation))]
public struct OverrideTranslationAndRotation : IComponentData {}

// This overrides translation as expected
[WriteGroup(typeof(Translation))]
public struct OverrideTranslation : IComponentData {}
 
// This overrides rotation as expected
[WriteGroup(typeof(Rotation))]
public struct OverrideRotation : IComponentData {}

Of course, an easy solution to this would just be to add both tags to the entity, but wanted to see if there was any other way I could make a component a member of multiple write groups.

Thank you!

edit: I should also mention that I have separate Entities.ForEach jobs writing to Translation and Rotation.

It should work.

Translation.cs

using System;
using Unity.Entities;
using Unity.Mathematics;

namespace Unity.Transforms
{
    [Serializable]
    [WriteGroup(typeof(LocalToWorld))]
    [WriteGroup(typeof(LocalToParent))]
    public struct Translation : IComponentData
    {
        public float3 Value;
    }
}
1 Like

Okay thanks for the sanity check on having a component be a part of multiple write groups.

Just did some more testing and confirmed that the issue was not due to multiple write group attributes on a component, but rather the query I was using for the job that writes to the Rotation component.

Issue was that the query for my Rotation job was also looking for read access to Translation components - this caused the query to NOT exclude the OverrideTranslationAndRotation component. Changing the Translation component to read/write access correctly excluded the OverrideTranslationAndRotation component.

Using .WithAll() fails to properly exclude the OverrideTranslationAndRotation component as well.

This makes sense to some degree as a query only excludes a component of a write group, when the query has read/write access to the write group type. Though I was expecting that it would exclude a component type where it had read/write to one but read only on the other.

Interestingly enough, this same behavior took place when I replaced the Translation component with a LocalToWorld so I could read the translation. I suppose this would be due to how the write groups are setup in the various transform components.

For my uses, I just need to read the position, so I’ll likely just use a CDFE.

Cheers!