Newbie tries making a fantasy city generator

I’m an artist and an Unreal-newb currently trying to come to grips with Blueprints and the wonderful world they offer. I’m not used to actually making stuff DO something except trying to make it look good, so this is incredibly fascinating to me. I’m also completely out of my depth, but relishing the opportunity to learn.

Long story short: I want to make a fantasy city generator, as a part of an even greater RPG scheme far out on the horizon. So far, I’ve reverse-engineering and stuffed my own meshed into the procedural flowerbed found in the Blueprints example project, since I couldn’t even begin to put something like that together from scratch just yet. That’s left me with seed-based, random cities that can be modified to whatever size and density I want, and which auto-conforms to the ground below it. It even looks kind of decent, if still a bit sparse and samey:

As a first test bed, this is lovely and I’m quite proud, but it’s pretty far from being usable for anything since it’s just spawning everything randomly without any system behind it. And it’s quickly becoming apparent to me that I could use some guidance if I want to take this to the next level.

So, I wanna begin a more ambitious Version 2, on which I’d welcome any input or links to relevant tutorials:

  • First and foremost, I wanna randomly generate the buildings somehow. I can build the parts, no sweat, but actually making the system for putting them together is still a mystery to me. Optimally I want some kind of snapping node-based system with interchangeable parts, so I could exchange window types and roofs and all that randomly from a set pool of meshes.
  • Then there’s the whole business of actually getting roads in there, and having the buildings actually line up to those roads. Judging from what I’ve seen out there, that stuff is harrrrrrd (but oh so cool).
  • Buttressed city walls that auto-conform to the shape of the city would also be really neat. I’m thinking the terrain editor’s spline tool looks like the right tool for the job, but I haven’t really tried it out yet. And how to hook that thing into a blueprint, well, that’s a whole other can of worms.
  • City quarters and plazas would go a long way towards making it look more like a city also - I’m thinking a sort of mini-biomes setup, with richer quarters and palace spawning sort of in the center, with gradually poorer quarters towards the edges.

I’ll come up with more stuff no doubt, and it’s really just a fun learning exercise for me. But if you happen to have any input, I’d really like to hear it. :slight_smile:

so , you are triying to do something similar to city architect

So far it looks really good, even if it is just random placement with no order.

You should build a Road Generator first though, once you get good looking road gen then you use your roads to define what and where your buildings will Spawn. Trying to spawn buildings then roads is the wrong way to go IMO.

Good luck though!

@diegor: Ooh, good find! You’re not wrong, from the looks of it - shall have to look more into this one. :smiley:
@DevilsD: Thanks! Yeah, you’re probably right, I’ve no doubt I am going about all of this in a quite impractical way. One step at a time, very new to blueprints yet.

So, I’ve gotten some way in now and managed to get a procedural building generator going, so I can get more building variation in there. I have two seperate blueprints - one just for making the procedural builings, and another that scatters them around, with the procedural building blueprint nested within. However, it is messing up my auto-conform-to-ground - I can’t get the buildings to stop using themselves as colliders, so I get new buildings spawning on top of others. Is there any way I can make a blueprint sort of “ignore itself” when it comes to collision, since I do want the buildings to have colliders? Or can you come up with a smarter way than I am using?

While almost kind of cool, it’s not quite what I had in mind. :stuck_out_tongue:

It looks like your tower has support cables in place holding it up…haha

As for the collision you can go and create a custom collision channel in your project settings. Then when you setup collision tell it to ignore the collision of that type.

Fantastic, thanks! Shall give it a go tonight. :smiley:

There is something very intruiging about the skyhigh building stacking :slight_smile:
Looks like you are on a good track Bluntie, keep it up!

I am also very new to blueprints and have been tinkering around with a very early prototype of a pawn class that spawns individual robot part actors based on a list of parts i predefined (and will eventually link to a “garage” user interface).

While im not entirely sure its applicable, ive found success and making an actor blueprint class for each specific robot part (arm, leg, etc) and spawing them to a variable “attachement point” in the main pawn class.

[Warning: free-flow brainstorming ahead]

How i see this being applicable to your case is to make classes for each category of each building type (tower, residence, plaza) so you have a class for spawning each individual building type. This way you can debug the logic more easily.

Next you make another blueprint class that contains the logic for spawning the buildings/roads. So this is the class that handles the seed values and some sort of logic that states “if my building is overlaping a road (or another building), find a different spot to spawn this building!” (You can use blocking/collision volumes that spawn along a spline similar to the procedural wall tutorial to handle this).

As for the quarters, you can have the main city spawning volume blueprint class generate procedurally placed “sub-volumes” that pull from one of several arrays that seeds the individual building constructor above to spawn a building that corresponds to the theme for the quarter you want to generate. This is an easier approach but less “organic”.

A more organic way to generate the procedural placement of “rich” core gradually becoming “poor” exterior, would be to have your spawning volume be just a central point (that spawns your plaza/townhall/castle) with the volume bounds being procedurally generated frm your seed (say, a procedurally generated “distance from the center cut-off” for each of the cardinal directions?). You can then have the “building type variable” (maybe an integer with 1 = “rich” and say 4 = “poor”) be driven by a lerp (with a modulo operator so the float fits into an int?) Based on distance from the center? This would make it very uniform and “concentric” though, so maybe feed an addtional multiplier to make the boundary between quarters “fuzzier”?

As for why your building spawns on top of each other, youd need to give us more details on how your algorithm works.

Good luck on your efforts though! And if you need another newb with a lot of wild ideas to help you out on your project feel free to shoot me a message :slight_smile:

@ConnorTheScot: Hahah, you’re not wrong. It’s pretty close to being cool in some weird way. :smiley:
@6ixpool: Some really good ideas in there, and very appreciated! I’m still getting to grips with how to think about stuff like this at all, so your ideas are very helpful. Thanks alot for the inspiration and for the offer of further help! This is all very much just a learning experience for me just yet, but it’s not completely unthinkable that it might become something more if I can spark my bosses’ interest - but that won’t be for a long time, if at all. :smiley:

@Bluntie - sorry i cant be clearer with how the logic operates. You seem quite adept with blueprints though seeing as how you managed to pull a basic city generator off despite your inexperience. Maybe my rambling will help nudge you towards the breakthrough you need.

Like i said though, I’m also very new to this all. If you want to collaborate on taking this to a step further, I’d be glad to lend my assistance, and be grateful for the learning opportunity :slight_smile:

(and it really shouldn’t take too long if we sit down for a few days to chrun out a useable/presentable prototype)

@6ixpool: No worries, man! You already set a lot of ideas off, and figuring stuff out is fun. :slight_smile: I have to turn you down on the collaboration for now though - I really want to make and figure out this thing myself, ain’t nothing personal. Feel extremely free to make your own version if you want though, I’d love to see how someone else might tackle this kind of task.

Now, for the Question of the Day, for whoever might have an answer:
I’m trying to spawn additional floors in my buildings, using a ForLoop a randomized amount of times, but I can’t figure out how to increment the position of each floor properly inside said ForLoop - they all move to the exact same position, and I’d really like them to spawn on top of each other, in a stack. It feels like I am missing something trivial here, but I can’t seem to crack it. Like, what I’d ideally want is some kind of node that lets me increment the position per loop. So, like, first floor gets moved 300, next one is moved 300+300, third is moved 300+300+300…you know?

Actually, never mind! I just had a breaktrough. I put the desired increment in a Float, then added it to itself per loop with an Float+Float. It’s not quite correct yet, but I can feel it’s the right direction. :smiley:

Youre on tye riggt track i feel. Try and store a variable called like “currentFloorZ” within the loop body with an operation like “currentFloorZ += floorHeight” (with “floorHeight” being a variable you can lookup thats inside the modular building actor).

If the floor heights are all uniform you can even just have it be like “floorHeight” * the current loop iteration (theres an integer pin you can pull out of the forLoop node for just that iirc).

Ideally you want to handle this by just manipulating the z vector by applying a “break vector” operation just so you dont inadverdantly move things around. (Although it could be just my paranoia talking)

Yep simplest way with that is just set an int for the “floor” which you increase per floor then times the floor height by the current floor. 3001,3002 etc

So many eureka moments tonight! :smiley: I am now at the point where I feel the basic system for the buildings is done. It starts by spawning a Foundation block, then adds a random number of floors on top, and tops it all off by adding a roof appropriate for the last floor-tile - that bit took me SO long to figure out, but I actually managed it in the end. I ended up scrapping the floor-height thing again (but thanks for input, guys :smiley: ), and went for a Socket-based approach instead, so I could have floors of many different heights, further adding to the randomness. Here’s a shot of a quick (not yet procedural, mind) layout using my debug blocks:

Welp, that’s the easy bit done, I guess. Now I should really cracking on that road-thing. Yipes. No clue. But guessing it’s something to do with splines… xD

Sockets on your meshes are definitely a good idea. That way you can actually start joining multiple meshes together on a single floor to create more unique structures out of it.

If you aren’t expecting to go inside the buildings it’s even easier but if you do want the internal structure to match up then you could apply some conditions to the sockets so you know if it needs a connecting structure to it to add an external wall etc.

@zoltanjr - pardon the very basic question, but would you need a skeleton to make use of the socket system? I made my own system by adding scene components and logic that finds and attaches my actors to each other via these components locations. Having a built in system to accomplish this would be incredibly helpful actually…

@6ixpool: For the very basic stuff I am doing, I haven’t needed any skeletons to use the Socket system. I just set them up manually inside the individual static meshes. I got started on it via this tutorial: Setting Up and Using Sockets With Static Meshes | Unreal Engine Documentation

Works for static meshes in pretty much the same way as skeletal mesh