- Home /
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.
Answer by Diekeke · May 31, 2013 at 12:27 AM
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! :)
Yes! This fixed it for me, too. Although rather than creating an orthographic camera, I created a normal perspective camera that's parented to the cloth object, and positioned so it's always looking at the cloth from a distance that ensures it's always 100% visible. I also have just "Solid Color" set for "Clear Flags", though I'm not sure if that matters at all. Either way, this definitely fixed it for me. Thanks!
Answer by cbm010888 · Jun 09, 2013 at 03:34 AM
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.
Holy shit, I was experiencing similar issues as described in this thread, and sure enough, adding a dummy camera to always look at my cloth objects appears to have instantly fixed the problem.
So it seems this culling problem would still exist as of Unity 4.5.1f3 Pro.
This is a particularly nasty bug because someone might spent time debugging the problem around InteractiveCloth, when in fact the true cause is a culling problem.
This doesn't fix my problem. It also causes about a 10 frame drop in performance. I have looked everywhere for a solution to this and I have found nothing works. The cloth disappears after its moving a certain speed. Does anyone know of any other ways of solving this. $$anonymous$$y cloth is parented to the player in my game. The player also needs to be able to move very fast...
Ok so I have verified that my cloth is not going outside the culling. Its actually getting physically left behind the parent. Sometimes If I turn around I can see it sitting back where I just was. Then eventually it snaps back to the right position.
Answer by Hazneliel · Jul 23, 2016 at 06:37 AM
You need to enable "Update when offscreen" on the Skinned mMesh Renderer
This will render the cloth even outside the culling
Yes then it reapears, but then the cloth gets somehow reinitialized when it reenters the rendered area which sometimes has really strange effects. For example: I have Sailboats with sails and when the sails reenters it sometimes wobbles in high speed around the mast and slowly gets in to the form it supposed to take. Often it is scrambled around the mast.
I get the same effect, when i disable and enable the Skinned $$anonymous$$esh Renderer, so i think that is what "Update when offscreen" is doing. So it only fakes it. I get better results when i enable and disable the cloth itselt too. I do that when raising and lowering the sails.