Never underestimate the back burner…

Okay, so it’s been a bit. Last week I went home to visit the fam, and since then I’ve been preparing for a certification exam. So unfortunately I haven’t been able to get much work done on the game in that time. However, before I started this little break, I had run into an issue of optimization…

sbc

The character above is robotic in nature and is essentially made up of a bunch of different parts. Additionally, not all parts share the same material. Some are gold, some are silver, and one actually cycles through a series of materials. Normally, when you create a character, it has a single material and the mesh is deformed around an armature. As far as I know, only one material can be shown on a mesh at a time in Unity. Because of this, I had to keep all the pieces of my little bot separate so that they could each get their proper material. So I parented each individual piece to its corresponding bone. This works well enough in blender, but when I imported the model into Unity, I discovered that I was now getting a plethora of draw calls. After tooling around a bit, I discovered that each piece of the bot had received its own Skinned Mesh Renderer component. According to the Unity docs, this is a no-no.

So I read up a bit more on it and discovered that non deforming meshes can use a regular Mesh Renderer component coupled with a Mesh Filter component. So I tried this, but alas, it popped the corresponding mesh into a different orientation and would no longer animate.

I decided to consult the brilliant minds of r/Unity3D and see what they had to say about it. I did receive a few responses but none that led directly to an answer. However, it did get the old noodle going and a I thought “Wait a minute… There’s twenty something parts of the bot, but only 3 materials… Maybe I can combine all the meshes that share a material!” So I fired up blender, combined the meshes, did the weight painting, brought it all into Unity, rebuilt everything, and voila! Dropped the number of draw calls by ~140.

I was actually kind of amazed at the difference. The number of meshes using the Skinned Mesh Renderer dropped from 21 to 3. Which was significant, but still, 140 draw calls? Wow… I mean, I’ll take it, but wahoo!

So anywho, the TL;DR of the whole thing is that if you have multiple meshes on a robotic character sharing a material, combine each part that shares a material, stop being lazy, and do the weight painting (it goes by fast on robots anyway). Here’s a screen shot of the before and after. In the first image, the white boxes denote the bounding boxes for the Skinned Mesh Renderers… Thanks for checking in!

sbc bounding boxes

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s