Obi Official Forum
Best way to disable then reenable rope? - 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: Best way to disable then reenable rope? (/thread-4603.html)



Best way to disable then reenable rope? - Bopter - 23-03-2026

Hi all!

I'm making a game where you try to throw lassos at other players. This requires a lot of spawning a rope, despawning it, then respawning it again.

Currently I do this by disabling the ObiRope and ObiRopeExtrudedRenderer components. When I need it again I reenable it by waiting until the rope is loaded then manually adjust the positions, prevPositions, and Velocities of all particles. Then I wait one frame to let things settle before reenabling the Renderer.

This almost works, except for a single frame where the Renderer shows its previous position. I cannot for the life of me figure out how to make the Renderer only show the new position of the rope rather than starting at its previous position. This also happens when I just leave the Renderer on the entire time.

Is there a better way to go about disabling/enabling rope or some kind of RendererRefresh I can call? I was considering teleporting the rope somewhere far away while disabled rather than disabling the component but wanted to see if there was a better way first.

Thanks!

Pic of the one frame issue:

[Image: T5Tm5FC.png]

Code:
// sets up the rope when reenabled

    private IEnumerator SetupRopeNextFrame(Transform startTarget, bool isStartDynamicAttachment, Transform endTarget, bool isEndDynamicAttachment)
    {
        while(!rope.isLoaded)
        {
            yield return null;
        }
        resetRopeLength();
        connectToBothTargets(startTarget, isStartDynamicAttachment, endTarget, isEndDynamicAttachment); //calls connectParticleToTarget() and lerpBetweenStartAndEndOfRope()
        _ropeIsActive = true;
        yield return null;
        ropeRenderer.enabled = true;
    }

// creates world peace
    public void DeactivateRope()
    {
        _ropeIsActive = false;
        startAttachment.enabled = false;
        endAttachment.enabled = false;
        rope.enabled = false;
        _isRetracting = false;
        ropeRenderer.enabled = false;
    }

// connects the ends to attachments
private void connectParticleToTarget(int particleIndex, Transform target)
    {
        Vector3 newPos = rope.solver.transform.InverseTransformPoint(target.position + new Vector3(0f, -.5f, 0f));
        rope.solver.positions[particleIndex] = newPos;
        rope.solver.prevPositions[particleIndex] = newPos;
        rope.solver.velocities[particleIndex] = Vector3.zero;
    }

// handles mid section of the rope
private void lerpBetweenStartAndEndOfRope(Transform startTarget, Transform endTarget)
    {
        //start at 1 because both start and end are already in position
        int edgeCount = rope.elements.Count;
        for(int i = 1; i < edgeCount - 1; i++)
        {
            int index = rope.elements[i].particle1;
            float percent = (float) i / edgeCount;
            Vector3 worldPos = Vector3.Lerp(startTarget.position, endTarget.position, percent);
            Vector3 localPos = rope.solver.transform.InverseTransformPoint(worldPos);
            rope.solver.positions[index] = localPos;
            rope.solver.prevPositions[index] = localPos;
            rope.solver.velocities[index] = Vector4.zero;
        }
    }



RE: Best way to disable then reenable rope? - chenji - 24-03-2026

I will not recreate rope if I develop this game. Just move the existing rope to a position that is not visible to players. (and disable Obi simulation after that)


RE: Best way to disable then reenable rope? - josemendez - 24-03-2026

(Yesterday, 08:06 PM)Bopter Wrote: When I need it again I reenable it by waiting until the rope is loaded then manually adjust the positions, prevPositions, and Velocities of all particles. Then I wait one frame to let things settle before reenabling the Renderer.

Hi!

Physics in Unity are updated in FixedUpdate(). This is often called less frequently than Update(), so simply waiting for the next frame using yield return null is incorrect: you must use yield return new WaitForFixedUpdate(), then wait for the next frame so that rendering is updated.

Otherwise the rope will appear in the pose it had during the last FixedUpdate() call before disabling it since no calls to FixedUpdate may take place during the frame where you enable it, so neither simulation or the shape of the rope will be updated.

kind regards