Posts: 7
Threads: 1
Joined: Jun 2022
Reputation:
0
hello,
I am using obi ropes , and using Solver_OnParticleCollision to detect there collisions
the games lags when ropes are to close to each other , can you help ?
thanks
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
13-07-2022, 03:11 PM
(This post was last modified: 13-07-2022, 03:13 PM by josemendez.)
Hi,
Every frame you're creating a new list, and for each contact you're removing Rope components from this list. I don't know how often this happens, but it has the potential to be slow (and cause a lot of GC).
Removing entries from a list has linear cost in the amount of elements in the list: the entire list has to be searched for the element being removed, then all elements past it have to be moved one entry back. So for each pair of particles in contact, you're iterating trough all ropes in the allNonCollidingRopes list multiple times. If you have more than a handful of ropes in the allNonCollidingRopes list, this will be *very* slow.
I'd use Unity's profiler to see what is the bottleneck, and if your collision logic is indeed the culprit, find a more efficient way to implement it.