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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Probuilder convert to mesh

Discussion in 'World Building' started by JDaze, Dec 23, 2020.

  1. JDaze

    JDaze

    Joined:
    Sep 19, 2018
    Posts:
    3
    How do I convert the probuilder object to a mesh? (The opposite of ProBuilderize.)
    I don't want to export to hundreds of objects.
    What I actually want is to create an assetbundle that doesn't contain probuilder dependencies.
     
  2. JDaze

    JDaze

    Joined:
    Sep 19, 2018
    Posts:
    3
    Found it! In the secret menu Tools > Probuilder > Action > Strip...
     
    joshua_salcido likes this.
  3. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    528
    You can also use the "Export" action if you want to save your meshes to the Project directory. Use "Export Asset" or "Export Prefab" (the former only exports a mesh asset, while the latter saves the entire GameObject + Mesh).
     
  4. minoaimino

    minoaimino

    Joined:
    Feb 18, 2015
    Posts:
    3
    Are there any way to convert from ProBuilder mesh to mesh(UnityEngine.Mesh) which can be used in script?
     
    Last edited: May 19, 2021
  5. minoaimino

    minoaimino

    Joined:
    Feb 18, 2015
    Posts:
    3
    I've got solved.

    Code (CSharp):
    1.                 var mesh = new Mesh();
    2.                 mesh.SetVertices(pbMesh.GetVertices().Select(o => new Vector3()
    3.                 {
    4.                     x = o.position.x,
    5.                     y = o.position.y,
    6.                     z = o.position.z,
    7.                 }).ToList());
    8.                 var indices = new List<int>();
    9.                 pbMesh.faces
    10.                     .ToList()
    11.                     .ForEach(o =>
    12.                     {
    13.                         indices.AddRange(o.indexes.ToList());
    14.                     });
    15.                 mesh.SetIndices(indices, MeshTopology.Triangles, 0);
    16.                 mesh.RecalculateBounds();
    17.                 mesh.RecalculateNormals();
     
    BuzzJive, NaoYuYan and Rickmc3280 like this.
  6. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    56
    I want to do the same thing, but I also want the uv maps. Your code doesn't pass on the uv maps, does it @minoaimino ?
     
  7. joshua_salcido

    joshua_salcido

    Joined:
    May 10, 2022
    Posts:
    12
    Confirming this worked for me in case anyone else wants to know.
     
  8. Brave_park

    Brave_park

    Joined:
    Nov 4, 2020
    Posts:
    1
    thanks thanks thanks!
    unity plz update menual.
     
  9. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    73
    @kaarrrllll

    Does not work with prefabs:
    1. When I run the "Strip..." command from the menu, it removes the script and the object seems to be fine, but when I exit prefab mode back to my scene and reopen the prefab, the changes are not saved. (Dirty flag is not set?)
    2. If I change some other properties on the object after the strip is done, and I save the changes then the prefab is modified, so the script is actually stripped, but the mesh has gone. So it's a completely destructive operation for prefabs, sounds rather serious to fix it very soon.

    Unity v2022.2.2f1.

    Steps:
    1. Create a ProBuilder object
    2. Make a prefab out of it.
    3. Open the object in the dedicated prefab scene.
    4. Run the "Strip all Probuilder scripts in scene" command from the Actions menu.
    5. Change something on the object (e.g. move it away a bit from its original position to make it dirty)
    6. Press Ctrl+S
    7. Exit Prefab mode.
    8. Reopen the prefab in prefab mode.

    Boom, the mesh has gone.
    No Probuilder, no standard mesh, just a "[none] (MeshFilter)" caption on the inspector panel:
    upload_2023-1-22_21-43-15.png

    Edit: This feature is dangerous even with scene objects as the resulting object after a strip works though, but if you just drag and drop it to make a prefab out of it, it loses the mesh without any warnings. Basically breaks the standard Unity workflow when operating with prefabs in a data-destructing way.
     
    Last edited: Jan 22, 2023