GhostDistancePartitioningSystem induces extreme CPU load

This is my first thread in this forum, dunno if this is the right place to report the bug so apologies if this is incorrect - but here we go anyway:

The GhostDistancePartitioningSystem induces an unneccesarily high CPU load independent of how GhostDistanceData is setup.

Unity version: 2022.2.16f1
NetCode version: 1.0.0-pre.65

After some testing with a copied custom Partitioning system it seems to be rooted in GhostDistancePartitioningSystem.cs Line 78

[BurstCompile]
partial struct AddSharedDistancePartitionJob : IJobEntity
{
   public GhostDistanceData Config;
   public EntityCommandBuffer.ParallelWriter ConcurrentCommandBuffer;

   void Execute(Entity ent, [EntityIndexInQuery]int entityIndexInQuery, in LocalTransform trans, in GhostInstance ghost)
   {
       var tileIndex = ((int3) trans.Position - Config.TileCenter) / Config.TileSize;
       ConcurrentCommandBuffer.AddSharedComponent(entityIndexInQuery, ent, new GhostDistancePartitionShared{Index = tileIndex});
   }
}

Because it keeps Adding the same component over and over instead of only adding it once in the beginning.

Solution: Adding the line [WithNone(typeof(GhostDistancePartitionShared))] above the AddSharedDistancePartitionJob struct fixed the issue. It changes the behavior to only add the component once. I imagine this is the intended way of this system, since the existing Component is updated during the Execute(…) of the GhostDistancePartitioningSystem itself above.

I will use my customized code for now until this is fixed. I hope it helps anyone trying to use the GhostDistancePartitioningSystem or even to fix the bug in the official codebase - if it isnt already :slight_smile:

Hey Oan,

Thanks for the report. This is a known issue, and is fixed in an upcoming version.

You’re exactly right on the program and the fix.