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. Dismiss Notice

Converting skinned mesh renderer to regular mesh

Discussion in 'Editor & General Support' started by Ronald_McScotland, Oct 6, 2014.

  1. Ronald_McScotland

    Ronald_McScotland

    Joined:
    Jul 30, 2014
    Posts:
    174
    Hello,

    The game I'm making has a lot of dead characters onscreen at a time. Since unity doesn't batch skinned mesh renderers, this adds a lot of draw calls. For the atmosphere of the game I'd rather leave the bodies laying around rather than fade them (or at lest have a lot before they start to fade). What I wanted to do is once they are dead and don't require any further animation, convert them to a regular mesh, and then combine nearby bodies into one mesh to reduce draw calls.

    I think it must be something to do with SkinnedMeshRenderer.BakeMesh, but I'm not sure how that works. Has anyone used this before or have any other ideas how to do this?

    Thanks.
     
  2. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hi I was looking for a way to combine skinned meshes but seen as noone has bothered to try help you I will give it a shot:D. I am mostly clueless when it comes to coding etc so hope this is a viable solution .

    Have 2 models one with bones and one without. Child the boneless wonder to the boned one and set render off. Once boney dies deactivate his mesh renderer and activate the mesh for our boneless buddy. Not sure how much a strain this would be on memory as you won't be able to delete the parent ? Otherwise you could just instantiate the boneless guy at place of death and destroy his skinned mesh version might effect performance?
     
  3. Ronald_McScotland

    Ronald_McScotland

    Joined:
    Jul 30, 2014
    Posts:
    174
    Thanks Tawdry. I ended up coming up with sort of a solution. What I did was create a script that used SkinnedMeshRenderer.BakeMesh on the first of each type of enemy to die, to get a baked version of the mesh in its last frame of the death animation. Then whenever a character of that type dies, his skinned mesh renderer is destroyed, and the baked mesh is instantiated in its place. It still doesn't combine the meshes, but at least its better having regular meshes lying around instead of skinned ones.
     
    Shamantiks likes this.
  4. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    You should still be able to batch those meshes.Can't you create a empty game object(call it deathstage) then as that char dies add its mesh as a child to the deathstage GO via script
     
  5. Ronald_McScotland

    Ronald_McScotland

    Joined:
    Jul 30, 2014
    Posts:
    174
    Does Unity batch child objects? I thought it only batched objects with less than 300 triangles (Unity Basic I'm talking about).
     
  6. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    I'm talking about the combine children script. You create a empty game object attach the script to it then you can child as much as 65k vertices worth of objects to it if they have the same materials they will be seen as a single draw.(usually u can pack much more than 65k verts in ranges for me from 100k to 800k). If u haven't been using the combine children script up to now I'd suggest doing so. One drawback is that if the item has a script running it will stop that script but otherwise its a brilliant tool.but does not merge skinned meshes.

    This should be what you looking for
    http://forum.unity3d.com/threads/combine-children-extented-sources-to-share.37721/

    just delete the $sign and numbers from the code name..I haven't tried out these scripts but should be the same as I'm using else do a search for combinechildren.cs if they don't work should find the right one.
     
  7. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    You could also try draw call minimizer on the asset store its free but I could not get it to work right it made a mess of my textures but it is supposed to batch and create a texture atlas just a shame it didn't work for me but maybe I'm not clue'd up enough and you can get it working?.
     
  8. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    There is very simple solution for it. Let say you had .fbx file that you imported. Dublicate it. Keep the original. And get the duplicated one, change its import settings, don't import animations and don't import rig. It will be imported as mesh instead of skinned mesh.