Most Efficent Way To Have Multiple Small Static Meshes

My project is a tile based game (all C++ except for making materials, which is BP) on which I will be making several towns. Each town will have multiple buildings with each occupying a single tile. These static meshes will be relatively simply (a few cubes at most). At the moment. I am using a class of “Town” which spawns separate Actor classes of “Building” and stores the pointers and details within a TArray. This is a relatively straightforward way of doing it, but I was wondering if there was a more efficient way of doing this? Otherwise I’ll quickly have a very large number of actors. I was thinking of maybe having the “Town” as a scene component and attaching the buildings as components rather than as separate actors? I did try to do something similar to this: -

but I was unable to get them to be rendered.

Also, would it be more efficient to use one large texture/material that is broken up into areas that all the meshes can use or to use individual smaller textures for each buildings? i.e. would the engine load the large texture multiple times for each mesh or would it only load it once and let multiple meshes access it?

Thanks.

You can use InstancedStaticMesh if your meshes share same mesh, but different transforms.
Also, TArray<UStaticMeshComponent*> is a nice way to do it. Your link is outdated afaik, you can dynamically add static mesh components to TArray<UStaticMeshComponent*> via AActor::AddComponent.
You can look at my old thread- it’s adresses same issues

Thanks for that suggestion; your project looked pretty cool. I followed Rama’s guide here for Instanced Meshes: -

and managed to get it to work; the Draw time reduced dramatically when I scaled it up! My next steps are: -

  • keeping track of the instances and removing/adding new runs during runtime (looks like you can access an instance array within the component, so should be straightforward)
  • investigate the Material offsets (which I believe you can do) for each instance
  • investigate rotation and scaling (pretty simple I hope)

Hopefully, I can generate random town with relatively different looking buildings from one mesh!

Then that takes me to the next step. I’ll probably have a collection of simple meshes (rather than just a cube). I was wondering if it would be better creating a different class for each shape of building, or whether you can have an array of InstancedStaticMeshComponents within the one StaticMeshActor class, and then call the AddInstance for which ever one you wanted? I am guessing that probably wouldn’t work but unfortunately my holiday free time is now up and it’s back to the day (and evening…) job so it’ll be a while before I can find out myself.