From 510cf5d5f2dcf88d5650bc20e0d528fb1453a94f Mon Sep 17 00:00:00 2001 From: Cihan Date: Wed, 8 Nov 2023 17:52:58 +0300 Subject: [PATCH] Fix TargetingSystem.cs not randomly skipping targets The GetEntriesInRangeWithHeap method is called with unfilteredChunkIndex as the first parameter. This parameter is intended to be an entity index within kdQuery, to ensure the algorithm does not find the entity that is performing the search. However, in this sample, the seeker entities are not included in kdQuery, so there is no need to skip any entity. Passing unfilteredChunkIndex seems arbitrary here, and we could instead pass -1 as a quick fix for the sample: Tree.GetEntriesInRangeWithHeap(-1, transforms[i].Position, float.MaxValue, ref Scratch.Neighbours); --- .../Assets/Miscellaneous/ClosestTarget/TargetingSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EntitiesSamples/Assets/Miscellaneous/ClosestTarget/TargetingSystem.cs b/EntitiesSamples/Assets/Miscellaneous/ClosestTarget/TargetingSystem.cs index e30eaa421..d038ac0fd 100644 --- a/EntitiesSamples/Assets/Miscellaneous/ClosestTarget/TargetingSystem.cs +++ b/EntitiesSamples/Assets/Miscellaneous/ClosestTarget/TargetingSystem.cs @@ -138,7 +138,7 @@ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useE } Scratch.Neighbours.Clear(); - Tree.GetEntriesInRangeWithHeap(unfilteredChunkIndex, transforms[i].Position, float.MaxValue, + Tree.GetEntriesInRangeWithHeap(-1, transforms[i].Position, float.MaxValue, ref Scratch.Neighbours); var nearest = Scratch.Neighbours.Peek().index; targets[i] = new Target { Value = TargetEntities[nearest] };