Search Unity

Question Edge collider points do not change

Discussion in 'Scripting' started by CoffeeTR, Aug 8, 2020.

  1. CoffeeTR

    CoffeeTR

    Joined:
    Jun 24, 2015
    Posts:
    7





    Why ?

    They do not change, there are different points. :S

    (Unity 2020.1)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    You cannot assign to array elements like this because those points are actually value types (Vector2). When you access the
    .points[]
    array, Unity is making a copy for you, which you are the modifying and dropping. It is not actually assigning it anywhere useful.

    Instead, copy out the points, change the ones you want, and put the entire points array back.

    Code (csharp):
    1. var points = ec2d.points;  // make a copy
    2.  
    3. points[0] = ...
    4. points[1] = ...
    5.  
    6. ec2d.points = points;  // put it back
    Almost all value type arrays (and a lot of reference type arrays such as
    .materials
    ) work this way in Unity3D.
     
    Last edited: Aug 8, 2020
    CoffeeTR likes this.
  3. CoffeeTR

    CoffeeTR

    Joined:
    Jun 24, 2015
    Posts:
    7

    Thank you , solved.
     
    Kurt-Dekker likes this.