Search Unity

ProBuilder setting UVs through code: Nothing happens

Discussion in 'World Building' started by SgtLame, Dec 3, 2019.

  1. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    68
    Hi everyone,

    I'm trying to learn how UV editing works through Probuilder API, and I have this simple example:

    Code (CSharp):
    1. List<Vector4> uvs = new List<Vector4>();
    2.  
    3. pbMesh.GetUVs(0, uvs);
    4.  
    5. // Random Vector4 for testing purpose
    6. List<Vector4> newUvs = new List<Vector4>()
    7. {
    8.     new Vector4(1.5f, 5.4f, 8.4f, 68.4f),
    9.     new Vector4(9.4f, 4.2f, 3.8f, 3.9f),
    10.     new Vector4(5.4f, 6.1f, 1.2f, 9.3f),
    11.     new Vector4(4.3f, 9.1f, 6.2f, 7.3f)
    12. };
    13.  
    14. pbMesh.SetUVs(0, newUvs);
    15. pbMesh.RefreshUV(pbMesh.faces);
    16. pbMesh.Refresh();
    Problem is, nothing happens, UVs are not updated. What's weird is that if I open the Probuilder UV editor and do any modification to a vertex or edge, then the above code works: The UVs are updated.

    What am I missing out?
     
  2. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    68
    I figured it out. Don't know if this is the best solution, but here goes:
    Code (CSharp):
    1. // Use this code before UV operations
    2. foreach(Face f in pbMesh.faces)
    3. {
    4.     f.manualUV = true;
    5. }