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

Feedback CombineMeshes weird results.

Discussion in 'Scripting' started by vagelis199, Oct 23, 2019.

  1. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    179
    So i have a game where you swap parts on a bike, so theres alot of gameobjects on the scene, i want before going to track reduce the gameobjects by combining meshes into a single mesh so i have a single gameobject since in race i dont wanna swap any parts. the problem is that combinemeshes combines successfully the meshes into a single one but theres no materials and the rotation is wrong.
    The script i use is straight from Unity Docs https://docs.unity3d.com/ScriptReference/Mesh.CombineMeshes.html
    The gameobject on inspector https://imgur.com/HF8f8Oe
    The result of the mesh https://imgur.com/ooAn8JH
    The meshes before combining https://imgur.com/lqYZxok
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    That color is sometimes called "no material magenta" and it means just what that name suggests: you're missing a material that one of the meshes calls for. You probably need to add a second material to the main MeshRenderer to match this material.

    Side note: Combining meshes might not even be worth it. Unity's dynamic mesh batching has improved radically over the years, and CombineMeshes hasn't changed a bit in all that time.
     
  3. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    179
    Ah i see, i was trying to optimize the game fourther and i notice that alot of gameobject are overloading the cpu but only if they are active, i'll try to reduce the materials i use instead maybe this way ill see an improvement.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Reducing materials will help (batching can't combine different materials, whether dynamic batching or through scripts).

    Have you used the Profiler? What, specifically, is taking up the bulk of CPU time?
     
  5. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    179
    When i have a scene with multple gameobject meshes like cars and trees the game has a huge frame drop,i cut the scene in parts and with trigger collision i enable specific parts of the scene to have less active gameobjects, i don't remember exacly if it was cpu or gpu related tho, thats why i assumed that if the player object (the bike) has alot of gameobjects maybe it might lower the performance which is the reason i thought about the combining mesh script which now makes me think this might not be the problem, i used the profiler but im not that good at reading it.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    In modern Unity, mesh/draw call counts can have an impact in large numbers, but they have to be really large numbers, especially on desktop.

    It's more likely that scripts or physics on the objects contribute the bulk of the slowdown, but it's impossible to say for sure without profiling.

    Also, if you're only testing in editor, check to see how much the slowdown is if only the Game window is open. Rendering the Scene and Hierarchy windows can be much more resource-intensive than the Game window for large numbers of objects.