Search Unity

Missing UV2 in prefabs, vertex count different in prefabs

Discussion in 'World Building' started by PatrickKa, Nov 20, 2019.

  1. PatrickKa

    PatrickKa

    Joined:
    Apr 30, 2014
    Posts:
    245
    Hey,

    I got some lightmapped prefabs and all of that works great for "normal" meshes but fails for ProBuilder meshes. Of course, the reason why its not working is that the UV2 is consistently removed for the mesh in the prefab. I guess even though thats annoying its intentional and I'm okay with that because I figured I could just store the UV2 along with the lightmapIndex, lightmapOffsetScale and work around this limitation this way.

    And that actually turned out to work at first! However I made some more changes to the mesh e.g. subdivide and extrude and it broke because the number of vertices stored in the scene mesh isn't the same as the same one stored in the prefab and thus my UV2 assignment failed. Bummer.

    Mesh stats in scene:
    491 verts, 658 tris, 2 submeshes uv,uv2

    Mesh stats in prefab:
    1256 verts, 658 tris, 2 submeshes uv

    I thought thats very odd and I got no explanation for this behaviour but it prevents me from working around the UV2 limitation. The next step would be to have another workaround for the workaround by storing the vertices, etc. as well. But its getting ridiculous here because I'm duplicating the mesh and bloating my prefab...

    Of course, I could also export an obj, etc. but this isn't a solution that scales very well because I'd need to re-assign materials, re-add colliders and scripts, etc.

    Theres probably ways to work around this with editor tools and such but I'd much rather finish a game.

    Looking for some ideas...

    Versions:

    Unity 2018.4.12f1
    ProBuilder 4.1.0
     
    Last edited: Nov 20, 2019
  2. PatrickKa

    PatrickKa

    Joined:
    Apr 30, 2014
    Posts:
    245
    Okay, so I tried to work around the issue of inconsistent vertex count by also storing the vertices and triangles but that caused some new issues with the materials then. I really didn't want to waste even more time on this and thats why I enabled Save Mesh To Asset as a final resort and that fixed all of my issues. Even though the warning is very disencouraging...

    I think the issue of inconsistent vertex count in the scene and in prefabs should be addressed. Its also very straightforward to reproduce and the discrepancy is most likely even larger for more complex objects.

    Reproduction steps:
    1) Create a new Unity project and import ProBuilder and have an empty scene open
    2) Open the ProBuilder window and create a new shape (created a Cube for me)
    3) Click Subdivide Object
    4) Drag and Drop the ProBuilder object into the Project Explorer to create a prefab
    5) Save the scene
    6) Check the Mesh on the ProBuilder object in the scene. You should see: 54 verts, 48 tris uv
    7) Click "Open" to enter the prefab edit scene
    7) Check the Mesh on the ProBuilder object (now in the prefab edit scene). You should see: 96 verts, 48 tris uv

    The increased vertex count can still be experienced when dragging the prefab into the scene or instantiating it at run-time. It persists in Play Mode and only the original ProBuilder object in the scene (as created in Step 2) maintains its lower vertex count.

    Versions:
    Unity 2018.4.12f1
    ProBuilder 4.1.0
     
    Last edited: Nov 25, 2019