Search Unity

Cloth coefficients are not updating

Discussion in 'Scripting' started by notforthebirds, Oct 20, 2017.

  1. notforthebirds

    notforthebirds

    Joined:
    Apr 30, 2015
    Posts:
    7
    I have set the coefficients of a Cloth object in Unity 2017.1.1f1. I update them 5 seconds in and they do not get appear to be updated in the Scene view. If I set a breakpoint, the coefficients have indeed changed, but the Cloth object still maintains the old values and behavior. I am attempting to clear out all the values for maxDistance to be the Maximum value. it seems to work, but the Cloth does not change its behavior. Any ideas? Thanks!

    Code (CSharp):
    1.            
    2.             Cloth[] clothObjects = FindObjectsOfType(typeof(Cloth)) as Cloth[];
    3.  
    4.             foreach (Cloth cloth in clothObjects)
    5.             {
    6.                 ClothSkinningCoefficient[] newCoefficients = cloth.coefficients.Clone() as ClothSkinningCoefficient[];
    7.  
    8.                 for (int count = 0; count < newCoefficients.Length; count++)
    9.                 {
    10.                     newCoefficients[count].maxDistance = float.MaxValue;
    11.                     newCoefficients[count].collisionSphereDistance = float.MaxValue;
    12.                 }
    13.                
    14.                 cloth.coefficients = newCoefficients;
    15.             }
     
  2. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    cloth.coefficients = newCoefficients; is a temp value created for the loop, once the loop completes cloth is removed.

    try a for loop

    Code (CSharp):
    1. Cloth[] clothObjects = FindObjectsOfType(typeof(Cloth)) as Cloth[];
    2. for(int i = 0; i < clothObjects.Length; i++)
    3. {
    4.     ClothSkinningCoefficient[] newCoefficients = clothObjects[i].coefficients.Clone() as ClothSkinningCoefficient[];
    5.  
    6.     for (int count = 0; count < newCoefficients.Length; count++)
    7.     {
    8.         newCoefficients[count].maxDistance = float.MaxValue;
    9.         newCoefficients[count].collisionSphereDistance = float.MaxValue;
    10.     }
    11.  
    12.     clothObjects[i].coefficients = newCoefficients;
    13. }
     
  3. notforthebirds

    notforthebirds

    Joined:
    Apr 30, 2015
    Posts:
    7
    I tried. It did not work. You are correct that it a temp variable created for the loop, but it is a reference to object. So changing the temp variable should change the referenced object. Also, the values are changing. It is working. It is just not rendering the new values visually. I appreciate your ideas!