Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by hne3 · Jan 08, 2018 at 03:18 AM · physics3dvertexclothskinnedmeshrenderer

Can add a constraint to a cloth at runtime, but can't remove one.

My code starts with one constraint on the cloth, defined in the editor. My goal is to remove that constraint and add another constraint at a different point, both in code.

 ClothSkinningCoefficient[] coefficientsCopy = cloth.coefficients;
 
 coefficientsCopy[vertexToConstrain].maxDistance = 0;
 
 // An unconstrained vertex seems to be listed as float.MaxValue in code
 coefficientsCopy[vertexToUnconstrain].maxDistance = float.MaxValue;
 
 cloth.coefficients = coefficientsCopy;

When I check cloth.coefficients[vertexToUnconstrain] after this code is executed, it's set to float.MaxValue, and if I pause the editor and check the constraints under "Edit Constraints", the vertex at vertexToConstrain is marked as constrained and vertexToUnconstrain is marked as unconstrained, but vertexToUnconstrain still behaves as though it is constrained in-editor.

To illustrate: Here is the cloth before I run the simulation. The only constrained vertex is in the upper center (which will be VertexToUnconstrain when I run the simulation).

The cloth before re-constraining

Here is the cloth after I run the simulation. I've selected the vertex in the upper left corner as vertexToConstrain, and vertexToUnconstrain (upper right corner) is no longer marked as constrained. However, it still behaves as though it were constrained.

The cloth after re-constraining

Thanks for your help!

afterexecuted.png (95.3 kB)
beforeexecuted.png (156.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by anselmkegel · Jun 12, 2018 at 05:00 PM

I had the same problem and fould a way to get it working. The code above is correct so far, but you need to re-enable the cloth component. Apparently the setup code happens in OnEnable(). So just disable and enable it again and it works.

     ClothSkinningCoefficient[] coefficients = cloth.coefficients;
     for (int i = 0, iend = coefficients.Length; i < iend ; ++i)
     {
         coefficients[i].maxDistance = float.MaxValue;
     }

     cloth.coefficients = coefficients;

     cloth.enabled = false;
     cloth.enabled = true;

It actually doesn't matter when you disable the component. You can do it before copying the coefficients or just right before re-enabling it. You just need to make sure to re-enable it after copying the coefficients.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

137 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Cloth Physics]How is surface penetration achieved in Unity ? 0 Answers

Can you apply physics to only part of an object? 2 Answers

Excluding Vertices from Cloth Colliders in Unity 5 4 Answers

How to walk around a 3D sphere? 0 Answers

Softbodies in Unity 3D 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges