07-08-2024, 08:06 AM
(This post was last modified: 07-08-2024, 08:11 AM by josemendez.)
(07-08-2024, 07:13 AM)vrtraining Wrote: Okay I have solved the issue by using the following new code
Code:public void ResetRope()
{
rope.ResetParticles();
ropeCursor.ChangeLength(initialLength - rope.restLength);
}
I didn't knew about ResetParticles() before, is there is any major difference between my previous and new approach. It seems to does the trick for me.
Hi!
ResetParticles() is much faster, as it doesn't take the entire rope out of the solver and then re-add it: it just resets particle data to whatever's in the blueprint. RemoveFromSolver()/AddToSolver() would destroy all particle/constraint data for that actor and recreate it anew, and trigger a full rebatching of all constraints in the solver.
However, ResetParticles won't reset constraints or elements (it only resets particles as the name implies) so if you're changing the length or the rope -which means constraints and elements are added at runtime- it won't work.
Also be mindful of *when* you call RemoveFromSolver() / AddToSolver(). In Obi 6 these are safe to be called anytime except FixedUpdate(), in Obi 7 calling them during Update() would result in them being called while the simulation is running, and you'd be pulling the rug from under the simulation's feet by modifying state from the main thread.
We'll upload updated API docs for Obi 7 later today, were these differences are highlighted.
kind regards,