How do I stop my game from slowing down?

Hello. I’ve been trying to place stuff on a grid (like in tower defence games), and when I’m placing stuff, my game slows down 50% (like from 120FPS to 60FPS).

Here is my Player Controller blueprint:

This is “Get Closest Grid Point”:

I’ve really tried thinking of other ways to do this, but couldn’t really come up with any alternatives.
Do you guys have any ideas?

If your grids are stationary and of equal sizes (like 32x32) then you can just calculate the grid number by using “Divide” nodes for the floats representing x and y locations. It’s much faster than using loops.

What’s inside of your “Grid” array?

It seems to me like those iterations cost most of your performance.
I can think of two solutions. Either you use a static grid system (based on coordinates) or a system where the player can only place towers on pre defined places which are their own actor.

In the latter case you simply create an actor and check with a trace which one you’re hovering over and display whatever there.

If you want to use the coordinates system you could take a look at this project:

It got a pretty good solution for this if you want to check it out. It’s using a static grid simply by X and Y values. (Just in case you want to check it out :wink:
I’ve used it myself in a TowerDefense sideproject of mine and it works great!

Thanks, I’ll take a look. :slight_smile: