Download

Create Random Board from Shaped Tiles

Hello Unreal community! I’m a VFX artist by trade, so I am familiar with Unreal, however I am working on my blueprint knowledge. As such, I want to learn from doing, and what I am currently trying to take baby steps in doing is create a digital version of a board game I have wanted to make for a while.

The first thing I am trying to do is build a board of tiles that are different shapes (Triangles, Squares, Pentagons, Hexagons, and Octagons). All of these shapes have the same side lengths, so they can all connect. What I was thinking about doing in theory is having board sizes to pick from, then it will create a board by attaching the tile meshes to each other based on the location of the attach points on each mesh (they would also need to rotate accordingly so the edges are flush with each other). Ideally I would be able to set the amount of each tile in each board.

Right now I have a board blueprint, and a blueprint for each shape that contains the mesh and the parented attach points (arrow components). Annnnnnnd now I don’t know where to go from here. ANY advice or guidance from here would be extremely appreciated!

Hi man,
its something like this ,
Be carefull with the unreal units, and scale of the mesh, try work clean having all scaled 1 .

its not possible without cheating.

unless the shapes dont have to have matching angels at every corner. then u could probably make it very easily. but im guessing u want everything to be symmetrical or whatever the word for that is. like. a square has 4 90degree angels. etc. etc.

Thank you so much for this, makes sense! I’ll try to get this in as soon as I can. I’m guessing I need to store those values for the the shapes in a data table and then reference them as variables?

It’s possible, I’ve built a paper prototype of this board mechanic. You just end up with spaces where tiles won’t fit obviously, but that’s actually desired in this case. Creates unique paths and corridors

Well i would store them in the blueprint that build the board, or there are any other blueprint that will need them?
I would suggest you to make a “structure” to store these exact needed variables and make easy to use variable.

Ok so I’m getting somewhere thanks to @Est_engine ! This is what I have so far, just working between 2 tile types for now, with their edge distances from their origins stored in variables:

](filedata/fetch?id=1845237&d=1608522014)

](filedata/fetch?id=1845238&d=1608522019)[IMG2=JSON]{“data-align”:“none”,“data-size”:“full”,“src”:“https://forums.unrealengine.com/core/image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==”}[/IMG2]​
So right now I’m placing the square tiles on sockets that are placed on the Octagon’s static mesh and then offsetting. I’m running into placement issues I think because of not being able to place the sockets in the exact location between points. Is there a way to get a more precise location with what I have? The solution would have to work with all other shape types, since their distribution will be random eventually.

Hi man,
Am i wrong or i see you are using a “Truncate” to some floats
that will convert a number like 14.41 to an int of 14 leaving you an incomplete distance ?

You can multiply vector to float too!

than you used the socket to get the locations ?
If you place these shapes center in the center of the origin axis, you can find all the location using perfect math!
A quick example is exagon,
If you make an exagon of lengt 1m, every side will be 1m and the distance from center to the sideDirection (T) will be a 1m too!

This all makes sense, however one thing I’m confused about is how will the tiles be placed radially out from the center in that case?

And yes hahaha, the truncates are a stupid mistake, I’m cleaning that up right now. They were included automatically by Unreal when I hooked them up for some reason.

I guess where I am currently stumped is how do I assign a random tile to each edge, while making sure that each new tile is the correct distance away and keep there from being stacked tiles and/or overlaps? Here is a quick sketch of what’s in my head for reference:

](filedata/fetch?id=1845523&d=1608587804)

Hi man,
what mean ? XD
““This all makes sense, however one thing I’m confused about is how will the tiles be placed radially out from the center in that case?””

You can assign a random tile making a “random integer in range” and “Switch on int” .
Watchout that the node “random integer in range” will give different number every time is called.
If you plug it to 2 print , it will print 2 values different.

Beware that you dont have to write the whole function/event for every shape!
You just create a custom event, Add (shapeA ) in (Shape B) at (link N) these should be variables (!)
So you just call an event/function “AddRandomTile” and it should get a random number, 3, get the 3°structure of data that should be pentagon (A structure is a pack of variable)
And feed this structure in the event, with a target (Tile) and a link( number)
So the event will, check if the Link of the target tile is avaible
Than will add the mesh based on the structures of data, of A, and B, and in the end should check if the new component overlap something esle.
If yes, delete it

You can check if there is an overlapping looping all the mesh with one of these 2 nodes
https://docs.unrealengine.com/en-US/BlueprintAPI/Collision/GetOverlappingComponents/index.html
https://docs.unrealengine.com/en-US/BlueprintAPI/Collision/IsOverlappingComponent/index.html

Let me know

OK, I got it to work on the first set of tiles!

Just need to figure out how to loop the operation on the new tiles:

https://media.giphy.com/media/lCbtd2…IwTv/giphy.gif

Wooo , So cool !
Thanks for share!

Well when you added these new tiles, you can save them as an array.
And cast again your blueprint for every tile in the array.
This event will refill the array again , so it could be forever
be sure to add a master count, so when you added 25 tiles stop the event.

Making a completely random tile like this, you may end up with just “FlowerMap”
A bunch of roadtiles that converge at the center.
If you want that some roads will meet to create a more complex roadtype
you can create some "search for bridge "
where you precalculate the amount of distance that you have between 1 or more tiles in various configuration.
And loop for all the tiles you have,
if some tile is at one of these “Bridge-Distance” you try to spawn the tiles and check ovelap.

So before moving too much further, I am continuing to have issues following the vector math involved for the placement of the new tiles on each loop. I’ve tried just copy pasting my nodes for the correct placement of the first set and updating to start/target vectors, however I can’t get the tiles to line up. This is as far as I can get with it looking like I’m on the right track:

](filedata/fetch?id=1846679&d=1609013018)
](filedata/fetch?id=1846680&d=1609013041)
](filedata/fetch?id=1846681&d=1609013048)
Result:
](filedata/fetch?id=1846682&d=1609013066)
New tiles are starting to line up, however no matter how I seem to try getting their locations to line up, it starts to break quickly.
Thank you so much for your help so far @Est_engine !

Hi man,
Made a quick , random add-Tile With only 1 shape Exa
hope that help you XD

This would be fantastic if I were using all of the same symmetrical shapes. The lining up of the different angles is continuing to be a problem.

Hi man,
are you still blocked?

Hey! Yeah, I’ve been messing around and still cant figure out a way to get the vectors of the tile edges and place the new ones accordingly.

Whoa , it took me a lot !
I made it a bit messy but it works.

For semplicity i changed the scale of the tils from 1, to 0.9 so i can see the gaps
but if you keep 1, there are no gaps, maybe sometimes some tiles overlap a bit but i already setted the collision to perfectly match the shape so i dont know XD

Wow that’s a ton of work, thank you for this! I’m going to run though all this soon and let you know if I have any more questions.