Instancing Static Mesh for an entire level [Optimization]

Hello everyone ! Hope you doing great.
Recently I was discovering the optimization in video games, because I wanted my game to work on any computer with +10fps at least xD. So when I build my level, I used more than 5000 static meshes for walls and ground, but as I understand, it create a lot of “draw calls”, despite the complexity off the mesh. So I searched on the internet and apparently I can use “Instanced Static Mesh” for it, but I absolutly don’t know how it works, and how I can implemente it to my game.

In the first screenshot you can see how the level is created, so I wanted to make it with instanced Static mesh, or anything else that can optimize my game.

And in the second, some part of the ground or wall have another material, so I don’t know either how it can work with Instanced Static Mesh.

If someone has an idea or know how I can optimize it, please you will be my savior!
Thanks in advance

PS: excuse my terrible english T_T

You can only instance things that are the same. They can have different location, rotation, scale etc, but they otherwise they have to be the same.

First you make once instanceable mesh like this:

347545-screenshot-1.jpg

You can set it’s details in the details panel, or you can use nodes to do that. Then, you make instances of it with:

To be clear, you only make ONE instanced component, and then use the other node to make many copies of it.

So, if I understand, I create my actor with these nodes, and place it on my scene, and now I have to copy the coordonates and rotation of every wall of the map and copy it in the node after called “add instance world space” ?

The first node ( add instanced static mesh component ), sort of gets the system ready. You will not see anything at this point.

The second node ( add instance world space, which does the main work ) will make your meshes appear, but they will actually be copies of the one main instanced mesh from the first node.

Imagine you magically had all the coordinates of you current stuff in an array, you could say

To get ready to add loads of cubes, and then

To actually put them in the level.

As far as getting all the information you need, meh, you’ve got your work cut out. Probably need to write a blueprint to put all the transforms ( location, rotation etc ) in the array, before you can place the meshes.

Also, notice this is a static mesh COMPONENT. That means this is all part of a blueprint, not the level blueprint.

Ok thanks for the fast reply, i’ll try to find another solution for optimizing my game, because I need to add more than 10000 coordonates in an array and I don’t have that much of time, like i don’t have 40h in front of me xD,so I will try to work with better LOD instead and lightmaps, thanks for your help!

You can generate the data using a blue print.
Make a new blue print inside do begin play > get all actors/components (depending on use), now for each loop get trans form and build the array by adding each loop entry to an array called"transforms" now run in simulation.
While running with the blueprint added to map copy the array entries

Stop simulation and past those entries into the array

You now have the transforms in a array format to copy int to the previous answers array. un the solution

Sorry tiered bad wordings but should be a good direction

Gl hf

No worries. If you tell me a bit more about you situation, I might be able to help. For example, you could easily write a BP the uses GetAllActorsOfClass and then stores all the transforms for you, then you can just instnace them :slight_smile:

So here’s my problem, I have made a level using modular assets, so all the walls are made of multiple static mesh, and the ground and the roof are made wife ground static mesh, I just changed the material when I needed. By the problem is having more thant 10000 static mesh in one little scene is causing performance issues, so I would try to optimize it. Here’s some screen to help u visualise the thing.

So here’s my problem. I made my entire level using only two type of static mesh, one for the ground and one for the wall. So for a room I copy paste my walls multiple times, and same things for the ground and the roof. But, in the end, I have now more than 10000 static meshes on my level, and it costs a lot of performance, so I’m looking for optimise it. So maybe with your system of instance I could instance all my walls and grounds.
alt text

EDIT: Big PS here: If you do try this, you’ll also need to save the instance data in the save game, otherwise when you save the level, everything disappears! Tell me if you get that far, and I’ll fill you in.

No problem, this is what instances are for. Let’s do it bit by bit.

First off, make a new empty level, because we’re going to get it working there. In the end, you’ll want to copy your full level, as we don’t want to trash anything.

1 ) Give every actor of the same type an actor tag. This is going to be for instancing, so it really just matters if they are the same mesh, it doesn’t matter if they are used for ground or wall, just that they are the same mesh. You might end up with 2 ( or 3 ) tags. You can just select all the tiles in one go and set the tag:

Notice it’s in the actor section, not the component bit.

A hint that might help you to select all of the same kind, if there’s a lot: you can right click on one and choose:

Make a new actor BP, instance_spawner, and drop it in the level.

The code in the actor is like this. Make a custom even ( get meshes ), and make it editor callable:

347584-screenshot-3.jpg

You can read all the actor transforms into an array like this

Notice that you don’t run the game, you can do this in the level editor:

Now we make another ( editor callable ) event to make the instances:

Notice, I make one ISM, and then add the instances of it. You can set the mesh here, or do it in the details.

When you press this button in the level, it will copy all of your walls ( floors etc ), and make instances of them, but we still need to get rid of the originals.

And this is how to get rid of the originals

Here, I put 3 ‘walls’ into the level and instanced them:

The system has copied the location rotation and scale. I know you can’t tell from there, but this is one thing, I can’t click on those walls separately, it’s like foliage, one big thing.

Then you can just save the level. BOOM - much better performance.

Tell me how you do :slight_smile:

PS: Try it on larger and larger amounts of meshes. I think it might take a few minutes to run on 10,000 or so…

PPS: Please also see what I added at the top. You need the blueprint to save the instance info in the save game. Otherwise everything disappears when you click save…

■■■■ that’s a great explanation ! I will definitly try it, hope it will work !

Final comment ( honestly ). Another way to do this would be level streaming volumes. It may or may not be less hassle: