Does scaling of mesh impact performance?

Ive got a mesh done in sketchup, and its huge in actual scale (apparently used the mm-preset). In unity I have to rescale it to 0,03 in order for it to have the size I want in respect to the default fps-controller.

Will rescaling a mesh have any impact over the performance?

It can; change the import scale so it comes in at the right size without having to scale it later.

–Eric

Thanks, I will do that :slight_smile:

Wow, the fbx-importer was already set to 0.01, and on top of that it had to be resized to 0.03. The mesh is like 3000 times larger than it should be :stuck_out_tongue:

Can you explain this? It takes the exact same number of floats to translate, project, and draw the exact same object at a different scale.

As I understand it if the mesh is non-uniformly scaled it needs to be sent to the CPU as well as the GPU which causes a considerable performance overhead. I might be wrong about exactly what is happening under the hood, but I do know that non-uniformly scaling objects in Unity (and Unity iPhone) is a bad idea and should be avoided.

And then you’re dealing with a bunch of meaningless numbers for scale. This is about making things make sense and work for human beings, not computers.

The docs say:

However, they don’t say anything about whether scaling an object after it’s instantiated will impact performance. (as far as I know)

If a mesh is uniformly scaled after being instantiated, does that impact performance as well?

I think this needs to be clarified in the docs.

The OP asked about rendering performance not workflow from my understanding. I wrote a couple of unit tests to verify if non-runtime scaling does impact performance and I can’t find where it does. The only way this happens is if you have some extenuating circumstances in the scene like the object is also an occluder (ala Unreal) and ends up partitioning out more/less of your scene which makes view-dependent performance better/worse. The transformation matrix is not witchcraft. It’s a known quantify. I could care less about human/computer workflow. I have a pipeline that works. I’m curious of why changing one value in that SPECIFIC matrix would slow things down at the run-time performance level (if it’s true).

There are some tricks you can do w programmable shaders to make it perform faster than a fixed-function pipeline (like skipping re-normalizing vert normals). Is this the kind of optimization with scale that the docs are eluding to?

There are some physics engines that handle scaling poorly, but overall, yes, you’re right, scaling should have little or no impact on performance. However, in Unity (although I’m not using iPhone stuff), it’s absolutely crippling.

Changing something’s scale on a frame-by-frame basis (even uniform scale) in Unity is very slow for some reason. Strangely, performing the same scale via animation clips, rather than through script, is fast as can be.

I ran into this with some animated HUD text on our last game. I wanted the digits of our combo counter in OMG Pirates! to “throb” when the number increased. Doing this with an animation clip caused no significant overhead, but performing the same animation procedurally through script would kill the framerate single handedly.

Hmm, haven’t tested with animation clips (did try changing in LateUpdate(), no difference), I’m doing a little scaling with animations, but not on many objects, so I assumed it was slow, just not as noticeable. But on about 200 objects, it’s absolutely crippling, and it’s happening without changing settings each frame. I can change one scale value in the inspector for the prefab I’m instancing, and has same effect as changing scale each frame in scripts, so in my case, it’s a fairly unavoidable problem. I mean, at this point, I’d have to write a shader for the object(s) just so I can scale it, shameful, shameful bug (or I might be able to get away with using animation(s) to scale it, glad you mentioned that).

It’s clearly a bug though, there’s nothing even happening on the objects, can even turn off shadows and colliders, same slowdown. Of course, there’s no difference between a bug and a design flaw if it’s not being addressed.

Edit: Nope, using an animationclip to do the scale didn’t make a difference, still absurdly slow.

is this really a “bug”, or a downside the the Unity engine? Does anyone know of any info regarding shaders that can help with this issue, ESPECIALLY for iOS?

Scaling should not matter at all , given that a full 4x4 matrix is being send to the GPU with every batch anyway… non-uniform scale matters only if you are using GLES lights and need to renormalize normals.

I’m gonna resurrect this topic and bump MikeMobile’s question.

I can’t find any clues as to why a script-based scale animation (localScale in Update()) causes major performance drops on the Iphone, while the same animation performed with animation clips or by external bone animation does not. Animating the rotation or position doesn’t display this behavior, so why does the scale? Does it punch the batching system in the face so that it has to rebuild some internal structures, or what gives?

Ok, this is all news to me…

If you scale it during run time, that’s really bad, go that. What about if you already have it scaled in the scene uniformly, is that bad?

I’m trying many methods of getting about these types of bottlenecks for our mobile titles. If there is a way to get around these calcs being so expensive(especially for mobile), I hope Unity or a 3rd part can offer insight/solutions.

zhx: We solved it by simply making animation clips in the animation editor for the scale altering. Lots of work and very awkward when the rest of the animation work is done programmatically, but it seems to be the only solution. Weird that this isn’t a bigger and louder issue, leads me to believe we’re doing something wrong. The slow-scale button is pushed and hidden somewhere…

Crazy Robot: As long as you don’t alter the scale programmatically during runtime, I’ve never seen any performance problems with the import scale, or non-uniform scales for that matter. Dynamic batching requires that the objects are of the same scale, though.

Got it! Thanks, I was getting worried!

@Fidde, thanks for the tip. This type of thing should really be handled by the engine in a more optimized manner IMO, but at least there’s a solution, albeit a bit of a time-waster.

Just ran into this issue myself. I am trying to create animation of procedural trees so i can’t really pre-calculate these.
I can confirm 2 things:

  1. If scaling is arbitrary (in x, y, z directions) then there is a significant performance hit. I was trying to render around 120 meshes corresponding to branches, and frame rate goes down below 10.

  2. As someone mentioned, if the scaling is uniform on the three axis, the performance is seemingly fine. I haven’t tested this enough but I still wouldn’t trust doing it every frame. There is however an oddity, which may relate to 1). If there is a sudden change in scale even if uniform, there is a huge penalty. If the scale change is more incremental, it seems fine. Very odd

Oh and I’m not developing on iOS. This is on PC.