Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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:
    36,780
    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.