Ropes Lagging - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Ropes Lagging (/thread-3523.html) |
Ropes Lagging - Gauri7 - 13-07-2022 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 RE: Ropes Lagging - josemendez - 13-07-2022 (13-07-2022, 12:51 PM)Gauri7 Wrote: hello,Hi there! Profile your game. Specifically, make sure that you're not doing something obviously slow in OnParticleCollision (things like looking for gameobjects in the entire scene for each contact, or similar stuff). If you could share the code you've written for OnParticleCollision I'd be happy to help with it. kind regards, RE: Ropes Lagging - Gauri7 - 13-07-2022 Thanks for the quick reply. Here's my OnParticleCollisionCode: Code: private void Solver_OnParticleCollision (object sender, ObiSolver.ObiCollisionEventArgs e) { RE: Ropes Lagging - josemendez - 13-07-2022 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. |