Hex grid is running oddly slow

I have made a hex grid which works as intended but it runs extremely slow and was wondering if there was any way to solve this. here are some screenshots of the code and the desired effect:

Instead of use staticmeshcomponents, use one instancedstaticmeshcomponent, and call AddInstance in it.

Here is an example project with similar stuff


I can’t see that you delete all the previous static mesh components before you add new ones, therefore everytime you call the construction script it adds and adds new ones, without remove the already existing ones.

You can’t see them properly in the viewport, because they are all at the same place, for a better debugging method get the count of current mesh components and print out that number instead of a string each time the function is called.

i implemented a set of code that will add the items into an array and display the length of it each time the construction script is ran and the number matches the amount of objects that should be in the grid.

well my plan was to do this with tile actors in order to give each variables as to whether they’ve been built on, has resources available on them, etc…

Do you now delete the previous added meshes? - Because in your images it’s not shown, that you do that.
For example get the root->get children->for each loop->cast to floor tile->destroy component if successful.
I just can’t imagine, that these few (simple) static meshes would cause any lag, except they’re beeing spawned over and over again…

With the “stat unit” command on, which segment causes the high ms?

no. that’s what i was wondering. if i added them to an array in the construction script and printed the count, wouldn’t the count not be different i it was adding new ones each time the script is ran, assuming that this was the issue?