12-01-2021, 07:34 PM
(This post was last modified: 12-01-2021, 07:59 PM by josemendez.)
(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);
}
}