Spline mesh component, draw calls and instancing

Hi, here’s some background for my main question:

I’m relatively new to UE and currently working on a mobile racing game. I chose using spline actors for building the track and its environment (fence, pillars, rocks on the roadside etc.). For the most part I used the methods described in this live training video.

Recently I started thinking about optimizations and pulled up some stats to check current state of one of my levels. What I’m trying to understand is:

  1. Why stats window and “stat rhi” cmmand shows different values (screenshot)? Triangles count and Primitives draw calls differs too much.

  2. The other question is instancing. I see that the stat window shows how many instances of a certain mesh is drawn. But the thing is that I’m using “Add Spline Mesh Component” in my BP, not “Add Instanced Static Mesh Component”, because it’s impossible to use for my needs. Does that still mean that the Spline Mesh Component is still being instanced even if it’s not described anywhere? I will be very happy if that’s so, I’m using Occlusion Culing and it works perfectly with the modular built track.

Would appreciate any answers, thanks!

The difference in calls tells you that you’re drawing a small ( ish ) number of very high poly meshes.

In the second table ‘instance’ doesn’t mean ‘static mesh instances’, it means ‘instances of this actor in the world’.

It’s looking like your main methods of reducing complexity are making the track model more low poly, and using LODs.

Hi, thanks for reply. Besides using further method of optimizations, like LODs, I’m trying to understand how the things work in UE, more specifically I’m exploring how the static meshes, which I add to my spline mesh component are beign drawn by the engine.

Here’s the thing. I’ve created a simple scene with my spline actor and added a fence mesh in it. Now I’m trying to measure draw calls which doesn’t differ so much whether there are hundreds of meshes or just a single one.

The thing which confuses me is that there is an Instanced mesh component exists, which I don’t use in my blueprint, instead of it I use this piece of code:

But, looking on the draw calls I’d say that my meshes are still being instanced. Am I right?

No. It’s just a terminology. All of your meshes are static mesh components.

Try changing that code to this sort of thing

Not literally this, but this concept. Add just ONE instanced mesh, set it to the fence, and then go into your spline loop making many instance of it.

You will definitely see an improvement.

I just tried what you’ve suggested and got completely opposite effect :grimacing:

What could go wrong?

You put the loop in the wrong place, I’m assuming.

You put ONE ISM in total. Set the mesh. Then add lots of instances.

So, all your spline code goes AFTER you have added the ISM. Only the AddInstance part goes in the loop :wink:

You’re completely right, didn’t notice how I missed that :upside_down_face:
I see a significant improvement in draw time. Thanks for the hint!

Now I need to understand how to bring back mesh randomizer through the spline for my BP, because currently it picks just a single random mesh from the array and instantiates it.

Ha! :slight_smile:

It’s basically the same concept for mesh randomization. You only need one ISM for each random mesh, the rest are instances.

If you put the meshes in an array, then you can make the ISMs in another array, and refer to that as you place the instances. The only random thing you need then is an integer.

You’re genius. Here’s how I handled it and the draw result is great!

Thanks for the help! :smiling_face_with_three_hearts:


Great! :slight_smile:

1 Like

good example thanks, but how to make the whole list of added meshes cyclically repeated, and not randomized? Do I need to somehow add or multiply the index of the spline and the array? sorry i’m a noob

You can just run around the array once to make the ISMs, then add the instances in a loop

Oh, a spline, hold on…



1 Like

Friend, I am very grateful to you, I haven’t slept for the third day because I was very annoyed that I couldn’t think of it and find at least 1 example of what I need, you’re just a master, thank you so much, it works!

1 Like

I decided to apply this method of arranging meshes for the spline mesh component, everything works, but only if the length of the meshes is approximately the same, and if they differ greatly, then the mesh is either strongly compressed relative to the previous one or strongly stretched forward along the axis, is it possible to somehow specify the length for a particular mesh by index from array? Thanks, sorry if I’m distracting you

The method I outlined above, will not stretch or squash. But you can have two array, one of meshes, and the other of how far to move on after placing each mesh.

the method you suggested is very good for arranging simple meshes or instances along a spline without deforming the meshes themselves. And I’m trying to apply it with spline deformation through the “spline mesh component”, as I understand that the principle of placement is different there. It seems to me that for each mesh from the array there should be a separate “spline mesh component” so that each one can specify a specific length along the axis, otherwise all meshes from the array added to one component are divided by the same number from the total length of the entire spline and since in my If they have physically different lengths, then one is stretched and the other is compressed. I need to somehow add the beginning of the next one to the end position of the first component of the spline mesh, and so on, and assign a mesh from the array and a length to each component … I guess so, maybe I don’t understand correctly

1 Like

Ok, spline mesh is very different from meshes on a spline :slight_smile:

Typical spline mesh code is

and the length of each mesh is dictated by where you put the points.

You can still choose meshes randomly, but it’s up to you when you make another point.

i tried using points as one of the ways that can work, but editing the spline itself becomes kind of hell, it becomes almost impossible to give the spline the correct geometric shape

1 Like

It does need practice :slight_smile:

But that’s how spline meshes work.

Unless you want a totally straight spline?