Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Get Particle Position
#1
Im using an older version of Obi cloth, 3.4. When I use GetParticlePosition() it only will return the correct position when the cloth object is selected. Is there a way to make sure the position is up to date when the function is called or something I overlooked. I've tried it with a new default cloth setup to ensure my apps cloth wasnt bugged.
Reply
#2
GetParticlePosition() in 3.4 returns a world-space position for a given particle, regardless of it being “selected” or not. I can’t seem to reproduce this behavior you describe. Would you share the exact code you’re using?
Reply
#3
(05-01-2021, 07:50 PM)josemendez Wrote: GetParticlePosition() in 3.4 returns a world-space position for a given particle, regardless of it being “selected” or not. I can’t seem to reproduce this behavior you describe. Would you share the exact code you’re using?

I made a new project and reimported the plugin. Im using the minimum code for the test.

Vector3 pos = cloth.GetParticlePosition (0);

            Debug.Log ("position = " + pos);


When its called in the Start function it works. If its triggered with a key press, ui button, or delayed in an Invoke it will return 0,0,0 until the cloth is selected.

Unfortunately the project is using unity 5.6 and an older obi plugin so it may just not work as expected.
Reply
#4
(05-01-2021, 07:50 PM)josemendez Wrote: GetParticlePosition() in 3.4 returns a world-space position for a given particle, regardless of it being “selected” or not. I can’t seem to reproduce this behavior you describe. Would you share the exact code you’re using?

Here is a video of the strange issue Im encountering. For this example I have a plane tilted so the cloth slides down to change position. I also had someone else test it and I made a pc build with the same results. I can send the files if you would like to examine. Thanks.

https://www.youtube.com/watch?v=NYG3ZAwD...e=youtu.be
Reply
#5
(05-01-2021, 07:24 PM)Visitor245262 Wrote: Im using an older version of Obi cloth, 3.4. When I use GetParticlePosition() it only will return the correct position when the cloth object is selected. Is there a way to make sure the position is up to date when the function is called or something I overlooked. I've tried it with a new default cloth setup to ensure my apps cloth wasnt bugged.

I have tested this on the example scene and the GetParticlePosition function does works. When trying to recreate this setup with the same trenchcoat file it goes back to not working. Any ideas on what would cause the issue? I cant find a work around for this problem and its fairly important for my current contract.
Reply
#6
(12-01-2021, 07:20 PM)Visitor245262 Wrote: I have tested this on the example scene and the GetParticlePosition function does works. When trying to recreate this setup with the same trenchcoat file it goes back to not working. Any ideas on what would cause the issue? I cant find a work around for this problem and its fairly important for my current contract.

Hi there,

Can you share the exact code you're using for this? I can't seem to reproduce this behavior. GetParticlePosition() does not use any editor code so it should work regardless of the object being selected in editor or not.

Edit: here's the code I'm using for testing. Make sure to tell the solver you need the position values (by using Require/RelinquishRenderablePositions), or they won't be updated unless required by other scripts. This isn't needed in newer (>= 4.0) versions.


Code:
using UnityEngine;
using Obi;

public class GetPosition : MonoBehaviour
{
    ObiCloth cloth;

    public void OnEnable()
    {
        cloth = GetComponent<ObiCloth>();

        if (cloth.Solver)
            cloth.Solver.RequireRenderablePositions();
    }

    public void OnDisable()
    {
        if (cloth.Solver)
            cloth.Solver.RelinquishRenderablePositions();
    }

    void OnDrawGizmos()
    {
        if (cloth != null)
            Gizmos.DrawSphere(cloth.GetParticlePosition(0), 0.2f);
    }
}
Reply
#7
(12-01-2021, 07:34 PM)josemendez Wrote: Hi there,

Can you share the exact code you're using for this? I can't seem to reproduce this behavior. GetParticlePosition() does not use any editor code so it should work regardless of the object being selected in editor or not.

Edit: here's the code I'm using for testing. Make sure to tell the solver you need the position values (by using Require/RelinquishRenderablePositions), or they won't be updated unless required by other scripts. This isn't needed in newer (>= 4.0) versions.


Thank you! It works now.



RequireRenderablePositions is what I was missing. My test video was just like the code used in the app to teleport a couple objects to some particle positions.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Obi;

public class Test : MonoBehaviour
{

public ObiCloth cloth;
public Transform testObj;
public Text text;

public void Teleport() { // triggered by button
     Vector3 pos = cloth.GetParticlePosition (0);
     testObj.position = pos;
     text.text = pos.ToString ("F4");
}

}

clothCtrlRt.position = innerLinerCloth.GetParticlePosition(50);
clothCtrlLt.position = innerLinerCloth.GetParticlePosition(51);
Reply