Procedural Generation of a Tilemap

Hello !
I’m making a 2D Infinite sidescroller, but i need to have random generated tilemap (from a base tile map, add some tiles at random places), how do i do it ?
Because there is no blueprint function for the tilemaps.

The generation could look like :
Start -> Decide what/which structure(s) to spawn -> Spawn it/them -> Decide which enemies to spawn -> Spawn them

I’ve planned to make a Blueprint to manage tilemaps spawning and dying (when they are too far from the player so the memory is not filled infinitly)
Thanks !

Edit : Made the tilemap manager blueprint, but to spawn them at a certain distance from player (only when there is not already a tilemap), how can i do it?

Thanks ! :slight_smile:

You just program it in blueprints. I will not write how to do whole thing because your idea is probably different than mine, bu I can give you

Some hints:

  • create PULSE dispatcher in some blueprint that is always in level, like player controller.
    All it should do is fire every 0.2 seconds (tested for mobiles and this was optimal timing for us)
    and it should have integer counter of pulses (do not worry your phone dies faster than integer will flop)
    you need pulse, because doing all that work on tick event is overkill, and huge waste of cpu power.

  • create Update tiles dispatcher, call it always when new tiles are visible on screen, when for eg player moved to new tile.
    now you need kill list (or survival list). For side scroller i would have 2 integers that describe columns.
    Everything between those integers (from column A to column B) survives, everthing else kills self.
    So you have those column blueprints with assigned “update tiles dispatcher”. If column of tiles is created do nothing.
    If column index is outside of survival range kill self. If column is not created and is inside survival area, start spawning tiles.

  • each tile (or column, vertical line of tiles) should be blueprint (or you should make some bp that kills tile meshes, your call here)
    all those blueprints on begin play should assign dispatcher “update tiles”, if they are not on survival list they should kill self.
    Again do left column index and right column index, everything outsided kills self. If your game screen has for eg 7 tile columns
    you need to add about 2 extra on each side (20-30% of whole screen)

  • now you need to create 2 functions: one that calculates 3d location vector to 2d tile index vector,
    other function does opposite, having tile index it should calculate central (or corner) point of tile.
    calculating central points and having all tiles with pivot in center greatly simplifies rotating of tiles, so i recommend this

  • ten you need (and you already have) tilemap manager.
    Assign pulse dispatcher. on every pulse create tiles in front of player. Yes this is small trick, you spawn empty column blueprint in front when update tiles dispatcher fires up, then those spawned column blueprints slowly (or at least not instantly) spawn meshes.
    Spawning meshes and lights instantly sometimes makes game shuttering, so you need to slow it down.
    Column blueprint should have array of items (tiles in that column) that it spawns, and it should spawn some of them, (as many as you can without shuttering). Best to make such array is by use of random stream with some set seed. I used cell index as seed this way sam sector (column) had always same random look.
    I suggest you implement this, because later in game when you add more visuals simple brute force spawning may start shuttering, and at that point you will have ready to use spawning mechanics.

We did this for our tiny game (evector) it is all made for optimizing on mobiles. However we spawned asteroids and spaceships in 2d space. So our game was double side scroller you can say. I may create some example out of it, but then maintaining blueprint with those monthly engine updates is pita.

Ps. whole message is in messed order, read it all few times before you start.

Hey, nice post but i don’t think it’s what i need.
My game is made of Chunks, a blueprint containing the map who chooses which tilemap to use, and generate random obstacles on it, it’s not the problem here.
I Need to spawn chunks in front of the player,so if the player moves and there is no chunk at playerpos+randomnumber it needs to spawn a new one there :stuck_out_tongue:
But when i try stuff, either the chunk don’t spawn, either they appear infinitly and end up using 3/4Gb of ram…
I’m going to try some more stuff again, but is there a way to spawn automaticaly a new chunk at x pos if there is no chunk ?

Got it working !
I Set up a delegate into the Level Blueprint to fire a function each second, the function do a raycast from below the player to a certain point distant from the player to check for collision, if there is a collision it does nothing, if there is not, it spawns a chunk.

Have a look on the Epic youtube channel they have an infinite runner tutorial that does exactly what you need