Interactive cloth disappears

Whenever the cloth goes out of camera, when the parent object that it’s attached to move back in frame the cloth sometimes is not there. Even weirder, if I pause the game and select the parent object the cloth reappears.

I tried multiple things already:
Turned off ‘don’t renderer when offscreen’
Changed attachment tear factor from 0.2 to 999 to 0.
Took of two way interaction
turned off all acceleration external or random
turned off gravity.

Nothing fixed it. The parent object is a rigidbody that is moved by applying a constant force. Presumably the problem is in the renderering not the transform, but I’m not really sure. Any ideas?

EDIT:

Alright I tried one more thing, setting the parent object to kinematic (So they wouldn’t move) then having my character move so that they were put out of screen, then when I moved so they were back in view, the problem didn’t occur. However, I do need them to move, looking at some other questions I heard someone talking about having the object only move with FixedUpdate (or LateUpdate, anyway, the one for physics only) so I’ll try that next, as it seems like now it’s more of a movement rather then a rendering problem.

LAST EDIT:

Okay yep that fixed it. Just edited this so that anyone who has this problem knows the solution: If your Interactive cloth that’s parent to an object that moves via a rigidbody is disappearing when the object goes offscreen (Meaning it does not return when the object returns to the screen), the problem is that the rigidbody is having it’s forces affected in an Update() that is not FixedUpdate(). Anyway, anything done to physics should be in FixedUpdate regardless, so you know, do that.

OKAY MAYBE NOT:

Alright now I’m a bit confused I was only testing it on one guy and switching it to FixedUpdate seemed to fixed the problem, but once I unfroze the other two guys and it started doing it again (Maybe it already was before that but just not as severely?). Yep just tested it again with just one guy and FixedUpdate, it’s still doing it. Absolutely no clue now.

Hey! I figured it out! Just add another camera with Projection → Orthographic and Clear Flags → Don’t Clear, then, on Culling Mask, just put the layer your object is, so your cloth is always visible by that camera. It worked for me, hope this helps you! :slight_smile:

Outstanding! Your solution solved a long-standing problem in my game.

I had noticed that selecting the InteractiveCloth object with Scene tab displayed would “guarantee” the InteractiveCloth object would not be culled. I did not think to create a “virtual Scene camera” in the Project Hierarchy, though. Good catch.

This problem may be related to reported problems with dynamic mesh not rendering unless RecalculateBounds() is called after setting the mesh to the renderer. I tried calling RecalculateBounds() every Update() based on the InteractiveCloth.mesh but I suspect this fails because the ClothRenderer has a copy of this mesh and changes to InteractiveCloth.mesh do not propagate to the ClothRenderer – which does not expose its mesh property.

Hence the need for your work-around. Many thanks.

A further note. In order to keep the orthgraphic camera view ‘invisible’ on the game screen, you can increase the size to 1000 which appears as a pixel or subpixel during gameplay. So create a camera as you indicated, after setting Projection->Orthographic, a Size parameter appears in the inspector. Change the size from 100->1000.

It seems to me (not verified experimentally) that this should be more efficient than the alternative – which also works – of rendering the Orthographic camera to texture using Camera.TargetTexture → select a render texture.

You need to enable “Update when offscreen” on the Skinned mMesh Renderer

This will render the cloth even outside the culling