Ways to generate tiled map/grid data?

I’m trying to generate a large procedural world based on chunks. I have my chunks loading and unloading successfully (finally) and now I’m trying to generate the world as a whole. Before UE4, I used GameMaker for a bit and managed to pull off what I wanted, but I’m having trouble converting something similar into Blueprints.

I want to procedurally generate a grid, and have each space represent a terrain piece (0 = city, 1 = road, 2 = forest, 3 = border).

As an example:
333333333
300101003
311111003
300102003
300102203
300102223
333333333

After I have the this little dummy map generated, I would go through and spawn the terrain pieces according to the XY coordinates of each tile.

Each terrain type would have it’s own algorithm of course (roads = drunken walk, forest = cellular automata), cities are just the default tile type, but what would be the most efficient/ easiest way to get this to work in UE4? In GameMaker I created a simple 2d array, filled it with my default 0 tile, then iterated through for each other terrain element, but it doesn’t seem like there’s an easy way to do that here, or am I missing something?

Any help is much appreciated!

I can think of half a dozen ways to accomplish this. It would all depend on complexity and scope. The most basic way that comes to mind…

[the top bit is me butchering the string as it comes with weird copy/paste formatting]

… results in something like this

If you want each tile to be a separate actor, create a base tile and a child for every tile type; then, instead of the Select node you could use SwitchOnInt.

If you have 50 tiles types, this will become a spaghetti very quickly in blueprints, though. You’d need to consider pre-processing the input data first. Turn the raw strings into more meaningful structs (each holding a class variable, for example).

When it comes to performance, you should investigate instanced static meshes and check [Zeustiak’s threads][3] (check his signature).

1 Like

That looks like you’re just converting that string into an array, right? I didn’t know you could do that, and it’s part of the solution, but I’m more looking for a way to generate that string in-game. And my tiles are level chunks that are blueprints with stacked procedural static meshes.

If I try to put more than a 20x20 grid of them, I can’t package my game to test it (runs out of memory), so what I want is to generate a placeholder map, and only spawn tiles as the player gets close to them. I have the tiles load/unload based on proximity, so that’s like 1/3 of the whole shebang working, but generating the proxy map ahead of time is what I’m having trouble with.

Ha. It seems like you have a much bigger fish to fry here. I was just trying to directly answer the question about the string array.

20x20 should be absolutely fine, 200x200 could be a bit more problematic, though.

Also, have a look at the 2dGridExecutionMacro ← Example usage. It can simplify grid generation a lot.

but generating the proxy map ahead of
time is what I’m having trouble with.

Do look into structs, it’s possible (if a tad awkward) to nest them, including arrays within arrays. You will need them anyway since you’ll want to save/load generated data. Unless you prefer regenerating from raw data.

If you have any specific questions, keep them coming. I’ll try to chip in on the topics I’m familiar things. Also consider posting in the forums - you might get a bunch of different approaches.

I appreciate the help. I’m not trying to hit 200x200, or anything crazy, I’d probably cap out around 50x50, not sure yet. I really don’t care how the map is generated, just that it is. I was considering heightmaps, I know those can be used for terrain, so I’m assuming a similar principle could work for anything else. I only need a few different tile types to be generated, so big pixelated texture with a single color representing each tile would be fine, as long as I could get it to generate the way I want.

Actually, if that is possible, it might be a decent method. I’m familiar with texture bombing. If those pixels could be extrapolated into the layout for a map it would be easy to overlay a bunch of different blobs and lines to form terrain and roads and such. Any idea if there’s a way to work that?

A year or two ago I did this same thing in GameMaker, where I spawned a map in an array using different algorithms. Worked great. If UE4 had 2d arrays, I wouldn’t be banging my head against the wall so much with this.

ue4 does have 2d arrays, just not in blueprint yet. If you know some c++ you could use a 2d array

Really? Everything I’ve looked up on the subject said there simply weren’t 2d arrays in UE4. If they’re in C++, I’ll look into it.

I realise this is an old question but it’s coming up in google results so I thought I would add my suggestion on 2D/3D arrays.

I have worked around the 2D array problem several times in UE4 blueprints in similar situations to the one you described (creating a map/grid) by using a map instead of an array with a vector as the type. This will give you a 2D/3D array fairly easily.

Unfortunately maps are missing some of the functionality of arrays (compare etc) and sometimes dealing with a vector as a “index” is a bit fiddly, but it’s still the easiest alternative I’ve come up with for 2D/3D arrays.

OP asked for an int based generation so… int it was. But this is not a reasonable method for anything bar the most basics.


Why not use a struct array that contains all the field data, including its own x/y/(z) index? Since you’re generating something, you’ll want to save it as some point, a struct comes in handy.

Or a DataTable? You could organise the data externally; or even paint-by-number and import that data via a *.csv file.

Have a look at the 2dGridGenerationMacro - pretty nifty for all things 2d (and 3d as well).


But yes, all arrays in BPs feel dimensionless, true!

1 Like

Hi, it’s 2023 and I’m attempting to do the same in UE5.3. I was looking at using DataTables and importing a .csv file for the data, just as you said. Could you lend some guidance on doing this, or point me in the right direction?

For context, I’m very new to UE and I’m doing a project on using AI (reinforcement learning) to generate 3D environments.