Created Map with Gridtiles and Noise, now I need to fill the lakes. Need Ideas


So I am recently playing around with grids and noise and I was able to create this Island.

Now the Noise gave me also some lakes which I want to fill/delete/change.
I just cant think of any logic on how to find out if the ocean tiles are actually not
ocean but “lake”. My last try was to start at one tile, check his neighbours if they are ocean and not land, then check all those neighbours that are ocean for their neighbours again and so on. I thought I could find the actual ocean this way and delete everything else. But this just ended in a big mess…

I bet there is a much simpler logic that I am just missing. Please send help.
Thanks :slight_smile:

Really hard to recommend something, not knowing how you coded it. But I’d say it’s sea if a block is connected to another block ( recursively ) which is at the edge.

Hi @ClockworkOcean

funny how its always you who responses :slight_smile: thanks man!

I am still working on it and I am still failing. I think I am on the right track now but still have some issues.
I was able to make my logic work (start at a certain tile, check if neighbours (left, right, bottom, top from start tile) are water, store them uniquely in “alreadyvisitedtiles” and “newfoundtiles” start same search for each “newfoundtiles”.
My problem now is that if I want to scann the whole map like this it crashes with the “infinite loop” error. I can only make approximately half of the map happen. (please keep in mind that I am still a complete beginner)

Now a few questions:

  1. Infinite loop errors are not always actually infinite, right?
  2. After a little bit of research I found that all the loops are tried to be executed in one tick, True? Therefore I assume I get the “infinite loop” error because its just too long/too much for one tick to compute.
  3. I found a setting in the project settings for the maximum loop iteration count, but even after adding a few more zeros it didnt let me run the code without the error, so I assume I really need to find a proper way to split up the workload. So is there a way to adjust the loops to the tick, so it just takes as much time as it needs or do i have to create “chunks” of operations and run one after the other?

As always, thanks a lot!


I thought someone came up with a funky way of doing this. Was that not you?.. ( who posted the previous land/water question )

To answer your questions: If the system keeps report infinite loops, tweaking the central max loop figure can help but is usually best avoided. The recommended approach is to deal with the looping problem.

Ok, I made an algorithm, but it’s not pretty, and it’s very inefficient. But it works immediately for about 120 square:

It basically revolves around putting all the meshes in an array, and being able to compute index from row/col and row/col from index.

Then, once the cubes are placed ( which, surprisingly, does take a few seconds ), it’s just a matter of:

The get material bit is just me checking if it’s water before checking if it’s next to a sea cube.

The NextToSea function looks like a bit of a mare, but it’s actually just checking the cubes above/below/left/right. One row looks like this:

and there are four ( five including the reject ):

To do this kind of thing efficiently is the kind of thing that ends up in scientific journals, so good luck with that… :slight_smile:

EDIT: I also noticed I have to apply it more than once, because the nearest neighbour thing doesn’t work on the first pass - yuck…

Hello again :slight_smile:

I can already check 2940 tiles + spawn 2940 new tiles in one run without an error.
So I feel I am doing pretty OK already. Its close to half the map. (scientific journal here I come?! :smiley: )
The spawning of the new tiles is just for me to visualize whats going on, so the yellow area is the ocean that is already scanned. I can also see this way that it seems to work great because it stops at land so at the end I will only have water that is actually ocean, then I can say that every water tile that is not ocean is actually lake.

Its similar to your logic just that I don’t check the material but work with my grid information.

But my question kinda remains, do you know If I can use the same code and just “run it on every tick until complete” to avoid the error? If so, what would be the blueprint equivalent nodes for such thing?
If something like that doesn’t exist I guess I will just split the whole map in a few chunks and then adjust my code for every chunk.

While I was doing it, I could see a much better algorithm is to work in rings inwards.

So, start with the outer ring of tiles, then you only have to compute the inwardly adjacent tiles ( so just one side ), then process the next ring in etc. Much more efficient.

Do you mean 2940x2940?

( Yes, comparing materials was a shortcut ).

So I just moved all of that into the construction script and here it works as I initially wanted it: Run this beast, take whatever time you need but just run it.

So its

  1. Creates the Grid (128x128) and saves each grid point and each grid point location into Arrays (0,3 sec compile time)
  2. Calculate and set grid tiles to “Edge of the map” (not yet in use, maybe useful later on) (still 0,3 sec)
  3. Create Noise and set grid tiles accordingly to Water/Land Arrays (compile time now 0,67 sec)
  4. Scann the map to find all Water tiles that are Ocean, remove them from Water array (now 7,6 sec)
  5. Create all the instanced meshes from the Water/Land/Ocean/MapEdge Arrays. (now 8,7 sec)

All of this in 8,7 Seconds. I dont know if its bad or good since I have no comparison. But the scann is abviously the big oof :smiley:
But your inward ring sounds like an improvement already. Yesterday I tried to start with the bottom left corner so I only need up and right. But it lead to some holes where the coastline is very curvy. I will try yours as well :slight_smile:


Yeah, 8 secs is pretty high. I mean, you’re doing good, but if you had a totally optimized algorithm, you could get it to < 1 I think, even in blueprint.

Wow, thats a motivational goal to work towards to. Thanks for the info :slight_smile:

1 Like