Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feedback Deleting collider invalidates collider id in ObiPinConstraintsBatch.colliderIndices
#4
(17-04-2026, 01:02 PM)nicity Wrote: Thanks for the quick reply! I will take a look for ObiParticleAttachment's UpdateAttachment
Changed type of the thread to be "Feedback", as the observed behaviour is a bit unexpected, of course it is for the performance sake

Sure Sonrisa It's a combination of performance + a Job system limitation:

Deleting an element by taking it out from a large array is O(n) in the worst case, since you need to move all elements after it one position back. Using swap is O(1) instead, so much more performant. You only change the index of 2 elements (the one being deleted and the last one) instead of potentially the indices of all of them. This is the reason why we swap entries in the collider arrays.

Either way, we're moving data around in the array. For the user to keep a reference to the data even when its moved around, the system must return a handle, which is a reference type.

The problem with this is that jobs in Unity don't accept managed reference types, so we can't pass the handle directly to a job and have it grab the index automatically. Instead, we pass the index inside the handle to the job by copying it, since it is a value type. This means that when the handle changes, the user must take action to update the data that gets passed to the jobs.

In future updates we'll try to figure out a way to simplify or entirely get rid of this pitfall. If you need help figuring out the exact fix for your current code, I can help if you share it.

kind regards,
Reply


Messages In This Thread
RE: Deleting collider invalidates collider id in ObiPinConstraintsBatch.colliderIndices - by josemendez - 17-04-2026, 01:29 PM