Procedural City Generation in UE4

Hello Everyone,

Currently I am trying to build an entire Wheel and Spoke city using blueprint. At this time I have been able to drawn the buildings (using a random unit vector) and make them face towards the center of the city (using some trig), but I cannot get streets to exist (I want 4 streets (One on the x axis, one on the y axis and two in between)). I currently don’t have a building model and am just using rectangular prisms.

The images shows current blueprint. What I am having trouble with is getting streets to exist, no matter what I have tried UE4 has done everything but. Here is a picture my current code:

If anyone can offer any help for how to create streets in the map I would be grateful.

Thank you,

Nathanalphaman

I have no idea, but my suggestion might be to create the streets first, then as the algorithm generates the buildings, check to see if it is street and don’t place a building there.

Alternatively, designate where the street will be after buildings generated and just remove any buildings in the way.

Perhaps use the algorithm to generate an array first, sort it all out in that first, then loop through the array and place the buildings or street mesh depending on the value in the array.

Admittedly tricky as it isn’t a normal grid, so not as simple as I was thinking.

I have tried using an inrange function to determine whether the building exist where I wanted streets but Unreal just didn’t care.

The array seems pretty good thank you for the suggestion

Have you considered using splines to lay out roads (Automatically or manually) and then have the roads generate the buildings around them when there is enough room?

No, let me try that right now

If you keep track of how big the buildings you want to generate are, at least the bounding box around them if/when they’re not cuboid, you could box trace the area you intend to place them (With some extra borders, preferably configurable) and plop them down if there’s nothing there, or at least nothing that blocks you.

The way I would do it (considering that I’ve been trying out different ways to do this procedurally but didn’t understand how to randomly spawn buildings within a boundary) is I would divide your city up between each road. For instance, have a class blueprint per city block that generates buildings randomly. Then just place them into the shape you desire. This isn’t as fast as simply generating the whole round city, but it can all be filled into a single blueprint. In fact, you can turn your city shape into an archetype, and every time you spawn the “Dynamic City object” you would get different results but using the same road layout.