Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Probuilder scripting api set UV mode to manual on all faces

Discussion in 'World Building' started by rotsin, Jul 8, 2021.

  1. rotsin

    rotsin

    Joined:
    Feb 22, 2013
    Posts:
    15
    Hey, I've been trying out this example from a previous thread:

    // Faces can reference the same vertex more than once. Use this function to get a distinct list of vertex
    // indices to work with.

    List<int> indices = faces.SelectMany(face => face.distinctIndexes).Distinct().ToList();

    // Project only the vertex positions that we care about by passing the indices parameter. The third argument
    // determines from what plane positions will be projected.
    var projected = Projection.PlanarProject(mesh.positions, indices);
    // Get a copy of the textures array, assign the new projected values, then re-apply to the mesh.
    var uvs = mesh.textures.ToList();
    for (int i = 0, c = indices.Count; i < c; ++i)
    uvs[indices] = projected;

    mesh.textures = uvs;
    // If you want your changes to UV array to "stick", the faces need to be flagged as manually unwrapped.
    // Otherwise the face UVs will be recalculated the next time `ProBuilderMesh.Refresh` is invoked.
    foreach (var face in faces)
    face.manualUV = true;

    It does not seem to work... :( when I open the probuilder mesh at runtime with the UV editor it's still marked as auto. Has anything changed from 2019, are there any extra steps I need to take to properly project and mark them as manual UV?

    Thank you for the help! :)
     
  2. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    It's difficult to say what the problem could be without seeing the code. Can you post the complete sample please?