Hello Everyone,
I am encountering a problem where a system continues to operate despite the DynamicBuffer Component being marked with [WithChangeFilter]. I understand that if even one entity within the chunk has read-write (RW) access to that component, the entire chunk is activated. However, in my case, I have verified that no entities on the server side have RW access to that dynamic buffer. Yet, the system persists in recognizing changes on the client side, even after I’ve disabled all server-side and client-side systems that might have RW access to that DynamicBuffer.
Thanks!
Job Sample:
[WithNone(typeof(PredictedGhost))]
private partial struct GameplayAttributesComponentReplicationForInterpolatedGhostsJob : IJobEntity
{
//GameplayAttributes
[ReadOnly] public NativeBitArray gameplayAttributesReplicatedComponentsMask;
[ReadOnly] public NativeHashMap<AttributeKey, ComponentType> gameplayAttributesReplicatedComponentTypes;
public EntityCommandBuffer.ParallelWriter ecbParallel;
private unsafe void Execute(Entity actorEntity, [ChunkIndexInQuery] int sortKey,
[WithChangeFilter] in DynamicBuffer<ActorGameplayAttributes> actorGameplayAttributes)
{
Debug.Log($"GameplayAttributesComponentReplicationForInterpolatedGhostsJob");
//Iterate, Check Replication Requirements and Replicate the Attributes
for (int i = 0; i < actorGameplayAttributes.Length; i++)
{
var attribute = actorGameplayAttributes[i];
//Check if Attribute Require Replication or Component non generated
if (!gameplayAttributesReplicatedComponentsMask.IsSet(attribute.Key.value) ||
!gameplayAttributesReplicatedComponentTypes.TryGetValue(attribute.Key, out var componentType))
continue;
//Replicate Attribute Component
ParallelWriterExtension.AddComponentDataUnsafe(ref ecbParallel, sortKey, actorEntity,
componentType.TypeIndex, 4,
UnsafeUtility.AddressOf(ref attribute.Value.Current));
}
}
}
It may be we are doing something incorrectly and bumping some version when we restore buffer or apply buffer changes.
Thanks for reporting. Are you able to repro on smaller project or test?
I’m unable to repro this myself by making a quick modification to our NetcodeSamples repro.
Confirmed via the Journaling window that there was no per-update RW access.
So I tried to repro in your project, and was able to. I saw the same result that you did.
But oddly: I also confirmed via the Journaling window that there was no per-update RW access.
Which implies [WithChangeFilter] is not working properly, or Netcode GhostUpdateSystem has a bug.
So removed the [GhostField] attribute on the PlayerMovementCommands. This didn’t help. Thus likely not the GhostUpdateSystem.
I replaced the [WithChangeFilter] with an explicit query (see code below). This fixed the issue! I’d recommend using this as a short-term workaround for now.
I’ll CC someone from the entities team.
using Samples.HelloNetcode;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;
[UpdateInGroup(typeof(GhostSimulationSystemGroup))]
[UpdateAfter(typeof(GhostUpdateSystem))]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct CommandsReactionSystem : ISystem
{
private EntityQuery _query;
public void OnCreate(ref SystemState state)
{
_query = state.GetEntityQuery(ComponentType.ReadOnly<PlayerMovementCommands>());
_query.AddChangedVersionFilter(ComponentType.ReadOnly<PlayerMovementCommands>());
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
new CommandsReactionJob()
{
world = state.WorldUnmanaged.Name,
}.ScheduleParallel(_query);
}
private partial struct CommandsReactionJob : IJobEntity
{
public FixedString128Bytes world;
private void Execute(Entity playerEntity, [ChunkIndexInQuery] int sortKey,
//[WithChangeFilter] in DynamicBuffer<PlayerMovementCommands> actorGameplayAttributes)
in DynamicBuffer<PlayerMovementCommands> actorGameplayAttributes)
{
Debug.Log($"{world} GameplayAttributesComponentReplicationForInterpolatedGhostsJob: {playerEntity.ToFixedString()} - actorGameplayAttributes.Length: {actorGameplayAttributes.Length}");
}
}
}
The issue is isolated to the WithChangeFilter attribute. The fix will take some time (Christmas holidays), but the Entities team are aware. We can only give release timings after the fix lands (and will do so).