Instances, what the point?


I was curios about how instancing static meshes works

I`ve done some tests
Here is the results
24 Meshes in one object from Max (51 fps)

1 Meshes copied 24 times in Editor (45 fps)

So what the point to use it? I am asking because I have a huge ship in Max and I want to find the right workflow to add it in game
The easier way to do it is straight from Max in one huge object, but this is probably wrong way in terms of performance but after this test I am not sure about it
Or maybe I am missing something?


I am guessing we’re talking about instanced static meshes here;

In terms of vertex processing (amount of polys / vertices) you won’t see any difference when looking at the entire scene. The biggest difference you should see (or actually not see) is Drawcalls. With mesh instancing, they should be equal to the drawcalls of one large mesh that has all polys combined. Without instancing, each of these assets create their own drawcalls. Subsequently each new assets drains your CPU. For some reason this does not seem to work in your setup, otherwise your performance would be equal.

There are stat tools that help you visualize this (stat units being one of the high level tools to track it down).

Now the reason why this is done: When you create the entire ship in one mesh, it will always be rendered entirely, unless you look away from it. Down in the cargo hold, you’d still have the engine room and bridge rendered. That is why you split the mesh up into chunks that make sense (cranes on top, bridge separately, etc). The renderer can then decide to skip objects that are outside of your view, they won’t be rendered. This does work for instanced meshes and separately added static meshes.

Bottomline: I’d check your setup and figure out why performance is not equal

Thanks for the explanation EchelonV

You are right, I have spend some time, looking for the answer

It turn out that UE4 by default do not combine all instanced static meshes and it can only be done with an InstancedStaticMeshComponent.
That`s explain why I am getting worse performance with a lot of istanced meshes because they have more draw calls than one huge mesh

By default, if you use multiple copies of a mesh it saves memory by only storing one. So that’s the tradeoff–save draw calls or save memory.

Another question about instancing and Draw calls
Here is the situation, you have 1 mesh with 10 mat ID`s and each id have their own material but this material is instantiated from the main mat

How much draw call we will have? All this Instanced mats will be treated like one in terms of Draw calls?

This is not true. Static meshes aren’t duplicated in memory. In both cases there is just single static mesh in object space at GPU memory. This mesh is then transformed at vertex shader to world space. Only difference is that without instancing each mesh is drawed with single draw call and transform is send to GPU(16floats). With instancing draw call command gpu to draw same mesh multiple times and current transform is indexed from array using InstancingID.

That’s what I said, by default it will store only one in memory, but if you want to reduce draw calls you have to use instanced static mesh blueprints

Thanks, I got this, but my question was about materials

Each material on an object is an additional draw call for that object

So if I have master mat and 10 instances of this material assigned to mesh ,I will have 10 additional draw calls for this object?

Just want to clarify to be sure, thx

Yeah, material instances are so that you can change something about a material without affecting everything that uses that material.

The main benefit of material instances is that you can update parameters in real time (in the editor and in game) without recompiling the shader.

Could be wrong about exact version, but in 4.8 or 4.7 this feature was added to base materials too

Thanks guys! Now it is clear for me

4.6 added allowing the changing of scalar or vector parameters in materials, but does that apply to a packaged game as well? That also doesn’t apply to Texture Parameters or Static Parameters.

The performance isn’t equal because Instanced Static Meshes are different from the editor-default instances of a static mesh.
To make use of Instanced Static Meshes, you’d have to make an actor blueprint and add the meshes as Instanced Static Mesh Actors and add the instances manually there.
So that’s why the framerate is poopy.