- Home /
Substract mesh from Skinned Mesh Renderer
Hi there Uniteers, I am in need of your help. In the process of optimizing our game performance, we have decided to look into combining all skinned mesh renderers into a single skinned mesh renderer containing all the other Skinned Mesh Renderer.
By using the script provided by duhprey and modified by Marble on the Unity Community forum, I managed to combine all our skinned mesh renderers into one:
Forum post about combining skinned mesh renderers
But combining all Skinned Mesh Renderers into one arises a problem. When attempting to disable a single "Character" (such as, when an enemy has been slain), it is not possible to disable the renderer, because all the other meshes will also get disabled, because they are all attached to one single Skinned Mesh Renderer.
So my big question is then: How can I disable a "Character" from a combined skinned mesh renderer?
I have two ideas:
1: When combining the skin mesh renderer, I will leave a copy of the original skin mesh renderer on the GameObject (Of course disabled). Whenever the GameObject is destroyed, I'll take the copy of the original skin mesh renderer, extract the mesh data, and substract it from the main Skinned Mesh Renderer, but:
I don't know how to do this, and I can't seem to find enough information to assist me. Any tips and tricks on how to proceed with this?
During such mesh manipulation runtime, is that to heavy?
2: Another solution would be to simply just move the GameObject out of sight (Underneath the terrain) but:
This approach seems very dirty
Would eventually lead into problems.
So, I am in doubt on how to proceed, and assistance would be appreciated.
If you absolutely must combine all your characters for optimisation then the easiest and quickest way to activate/deactivate areas would be to keep a copy of the triangle array for each character($$anonymous$$esh.trangles) before you combine them. Search and remove that array from the main list when you want to deactivate that character and insert it when you want to reactivate it.
Hmm, sounds reasonable. What about perfomance in such case? Something I have to worry about, if we are talking rational meshes with maximum of 300 verts?
If it's not a function that is run every update and it doesn't cause noticeable lag spikes then optimisation is pretty much a non-issue. Either way removing a section of int values from and array isn't very costly.