Cloth simulation doesn't work after disable mesh

Hi,

As the title say, I got some Cloth problems. I got a mesh with the Cloth component and the Skinned mesh component.
I have two characters: The basic one, without cloth, and the second one with the cloth.
By pressing E, I can switch of character. The first time, i switch to my Cloth character, the physics works. When i move it simulates as a cloth. But when I switch to my basic character, then press E to take back the cloth character, it doesn’t simulate the physics anymore.
Is this because I disable the character when I switch each time?

// For the Basic Character

public class PlayerController : MonoBehaviour {

public GameObject peluche;
public GameObject SkinBase;

[HideInInspector]
public bool move = true;

[HideInInspector]
public bool _isSwap = false;

}

// Update is called once per frame
void Update () {

if (Input.GetKeyDown(“e”))
{
if (!move)
{
return;
}
if (SkinBase)
{
peluche.SetActive(true);
_isSwap = true;
SkinBase.SetActive(false);
peluche.transform.position = transform.position;

return;
}

}

// For the Cloth Character

public class PlayerController2 : MonoBehaviour {

public GameObject peluche;
public GameObject SkinBase;

bool move = true;

// Update is called once per frame
void Update () {

if (Input.GetKeyDown(“e”))
{

if (peluche)
{
transform.position = SkinBase.transform.position;
SkinBase.SetActive(true);
SkinBase.GetComponent()._isSwap = false;

peluche.SetActive(false);

return;
}
}
}

I have noticed the exact same issue- cloth works on 4 different character models when the artists are working with them in scenes in which they are always enabled, but when our production app disables all avatars (the entire root GameObject of each) before enabling the one the user has currently selected, the cloth doesn’t simulate on the re-enabled avatar. Moreover, when I then toggle the Cloth component of the enabled avatar off and on in the editor at runtime (toggling it off and on from script has yet to show any effect…) the cloth does begin simulating but usually ends up in weird non-tenable edge-case positions and also tanks the app framerate.
So I suspect this is either a bug or a “feature.”
In my case, this is on 2017.3.0f3, but the project is NDA so I can’t post code samples.

Edit: looks like as of my last experiment, I forgot about a few other circumstances that were also disabling & enabling the avatars. When I put a script on each affected avatar that toggles the cloth on disable & enable, it appears cloth now does run. Still tanks framerate and gets a bit stuck at times, but it at least runs.

public class ClothToggle : MonoBehaviour {

Cloth[ ] cloths = { };

// Use this for initialization
void Start () {
cloths = GetComponentsInChildren<Cloth>();

foreach (Cloth c in cloths)
{
c.enabled = false;
}
}

private void OnEnable()
{
foreach (Cloth c in cloths)
{
c.enabled = true;
}
}

private void OnDisable()
{
foreach (Cloth c in cloths)
{
c.enabled = false;
}
}
}

1 Like

Any workaround to this issue?

I posted a workaround in this thread:

1 Like

Yes, It worked well for me, Thanks a lot :slight_smile: