How to do many buildings (strategy game) properly performance wise?

Hi, so I am trying to build strategy game with fixed grid (imagine 3D sim city 2000) and whilst I didn’t encounter any problems so far, I don’t know if I can (update: I cannot) make say 512x512 grid of building actors (empty building, factory, house…), or if I should already think about some other approach (update: yes I have to) So question is: can I do it just like that, or should I have some specific approach to it?

PS: that grid isn’t static, as in it’s a set of coordinates for actors and those coordinates change during gameplay. If that is important for some solution.

UPDATE: So it is definetly too costly (as I am able to instance thouslands of buildings, yet straightfoward mesh drawing struggles after only hundrets of buildings). Which means, that I am really interested in “typical” solution to it. I am fully able to instance meshes, but I don’t know if I am able to instance Actors, or if I will have to tackle it in some specific way. Now I am already having problems with mouse click detection (which building did I click on, as it is just an instance and afaik they don’t have any kind of handle :frowning: )

So I built a really simple city builder where I can build Houses(blue boxes) on a grid style canvas. But I can’t build on areas that block my houses like a river. I can also bulldoze my houses if I want.


To do this, I built two Blueprints and played with the player controller BP.
My first Blueprint was the grid which I called Gridmap. Which is just a bunch of box components that are carefully aligned to make my grid.

My second Blueprint is my House blueprint. Nothing to show there, it is only a static mesh in the shape of a cube very well centered.

Finally I set up my player controller.

So everything works based on what is under my cursor during the time that I click. Break up the Hit Result to find very useful nodes. Here we are looking specifically for the Gridmap component’s locations, so I used the Hit Component to get those locations. But I make sure that I can only build if the Hit Actor returns Gridmap from his class, otherwise it does not build. Which makes it very easy to make it so that I can’t build in case of a river or other things that could block my build site. All I need to do to prevent from building is hide my grid with either the river, other buildings or with invisible Blocking Volumes so that the Hit Actor doesn’t return my Gridmap. Finally to destroy the houses I used the same principal; if I right click and my Hit Actor returns House Class then it deletes the return from Hit Actor.

To place and restrain bigger buildings or areas (512x512 grid), Box Overlap Actors node could determine whether there is room or not.

Hopefully this was helpful for you!

Wow, thanks, I will use few of your things (I have a grid of actors, and I was just about searching for mouse interaction, now I don’t have to) and video example is greatly appreciated.

But what I am asking is if I can really do say 512^2 actors without some performance hit from drawcalls or anything like that. Because that would mean using like 250.000 actors, whilst each one would be building (with textures, maybe animations and so on) - if that is wise, or if I should do something entirely different, like, say, having actor for each TYPE of building and than one actor would draw all of his buildings on the map. I could imagine something like that, but I am not sure if I should/have to do it like that.

but again, you accidentally helped me with other issue that I was just tackling.

I had a feeling that your question was more in depth :slight_smile: Unfortunately until I try it out, I can’t tell you for sure either. I’ll keep this in mind though, and maybe I’ll find something. Otherwise, I’ll be looking forward to the solution!

so long as the models are not too complex i cant see it being an issue but the only way to know for sure is to try

it isn’t an issue if you have only few models… but it becomes an issue pretty fast.

even with low poly models?

If 4poly is low, then yes. I can show thousands of instances without any noticeable performance cost, yet if I span it as a mesh, I can do only tens, maybe hundreds. So back to the issue, How would I do thousands of buildings whilst still having the ability to click/control each one of them? How should I instance it, how should I use actors?

what do you mean “span it as mesh”?

i would set it up to use as few meshes as possible, and re use them for different buildings with alternate textures (or again the same textures but color/other overlays to make them visually different). Having not tried what you’re asking i cant be 100% certain it will work, ill have a ganders at some point and see what i can come up with.

Well, yes - that is what I am basically doing - instancing meshes (using one mesh and instancing it on thousands of places). But that means, that I cannot (as far as I know) have one actor for each house. So I am interested in general guidelines how to do it in Unreal, what is most effective way for it (shall I have actor for all buildings? for building type? how to do clicking on instances, how to change those instances and so on).

right i think i follow now. sorry for the lack of understanding.

Don’t use the mesh as whats placed, create a blueprint called say “building” then you can right click that blueprint and create a blueprint based on this and it will create a child and say that’s a “hospital” then create another and that’s a “shop” then each one can have its own individual event graph, but you would have to manipulate the instances material using the construction script so you get the visual differences. As for interactions such as clicking the building, id have that setup on an interface that is used by the building blueprint and therefore used by “hospital” and “shop” through inheritance but can be coded individually (I THINK you can in “building” create the click event also rather than code individually and “hospital” and “shop” would use that code also, but i’ve not tried). I realise thats a wall of text, ill put together an image to illustrate.

Yeah, thanks, this seems reasonable, I will try this way when I get to it (fighting with something else right now). But I can see how I could do it this way.

Whilst I don’t know if my current solution is most effective/nicest/logical, I have actor for each building (or lack of one) which isn’t performance heavy, and it’s visual representation is instanced in different actor. I will probably have something like building parrent, which will hold all static meshes, while childs will draw them.