Help regarding blueprint and UMG

Hello forum!

I have a huge task ahead, and I’m not sure how to start or what even to do, or how to do it.
Here’s the concept:

You have a menu in which you can choose between various buildings that you wish to place in the world.
To each building, a foundation must be placed, and built using resources from around the world (stone, wood, gems, etc.)
Once the resources has been gathered, the foundation should turn into the house that was chosen from the menu.

Consider the following:

House from the menu (thumbnail)

tmp.PNG

When this is clicked, the foundation can be placed like so:

tmp1.PNG

Once the resources has been placed, the foundation should turn into this:

tmp2.PNG

I’m not expecting an answer to the complete flow of this process, but simply asking for guidance, ideas, tips and tricks.
I have no idea where to start (except from making the UMG menu), and I’m not sure how to tackle this task.

Any help is appreciated.
Thanks in advance!

Hi,

I have implemented something like this and although I am still working on improving this, it is mostly working. In my game, I have AI controlled characters that will do the building in a mouse-controlled top-down game. Your first screen shot suggests that you are using a first person approach, so details might vary of course.

I have the UMG menu set up in a way that clicking on one of the buttons calls an event in the PlayerController class. This event will spawn an actor of the specified building class (The class can be selected as a property of the UMG button that triggers the event and passes the class as a parameter to the event). Then, a reference to the spawned actor is saved in the PlayerController. During the PC’s tick, I do a raycast to get the point where the cursors hovers over the floor/landscape and update the building actors location to be that point. This way, I get a preview on where the building will be and how it will look like. You might want to change the collision settings on the ‘proxy’ building to prevent it from kicking around other actors in the game - I also have a function that checks whether the proxy overlaps with an existing actor and changes a material parameter in the proxy actor to give it a red tint when it cant be placed. The proxy might also implement other functionality like snapping to existing buildings if your gameplay would require so.

On mouse click, I create a new copy of the building at the current position of the proxy and destroy the proxy. The new building will notify my AI that one of them needs to get active and collect the resources to construct the building. For this, my building base class has an array of a custom inventory item class which represents the required cost for this building to be constructed and the AI figures out where to find those resources and transports it to the construction site via a behaviour tree. At this point, your building will probably be in the ‘foundation’ step and once the resources are collected, it might change the mesh to be the full building or it might destroy and replace itself with the actual building blueprint. How the resources are collected will of course depend on your gameplay but I think having some type of inventory property/component on your building to store the resources and trigger the build process once the last required resource is added to it’s inventory seems to be a good solution.

Yeah, I think I have something that might work. I’d love to have this menu be dynamic (easier to add new structures), but I guess that’s an even bigger task that might be implemented later.
I thank you for your response!

Split your task into smaller ones first, do not develop all this at once.

I would start with just placing floor tiles. So later your menu has something to do, and you know types of actors you are using. For eg. do you want to have static materials on tiles, or customizable trough menu? and all those details that are unknown to you until you make tile placing mechanic. So tile building first, out of just one actor.

I suggest you make all tiles as actors (separate blueprints). All should have exactly same functionality (ie. code), so for this inheritance and child actors are best. (when you have parent class ready, you can create inherited classes that change mesh, materials etc, but have exactly same code under).

You need snapping to some grid, and best would be local grid to each building. So first actor you place will be "corner stone"it needs some flag, and way to be found. (ie. function that finds either current corner stone or closest one). When your character blueprint finds that corner stone, it asks for size of grid and its rotation. Then you should have function that calculates locations and rotations of any spot fitting that grid.

When you are placing new tile in grid, you should display transparent shadow of tile in closest matching spot.

Then add keys for rotating 90geg, moving up, down, left,right to next snapped to grid position. And some key that locks current corner stone, so you can build huge structures that are on same grid (like move trough half of map and still have tiles placed on same grid).

Thats all for now, you should have better system than fallout 4 did.

PS.
I am not sure how advanced you are, but just in case watch (and search) tutorials for:
blueprint communication
inherited blueprints
blueprint components

also be aware that this (runtime building) creates dynamic meshes that means static lighting will be messed up. So for developing time use only 1 directional light and simple materials, no need to suffer with slow editor until you are ready for better looking game.

I’m not sure how you create your menu at this time, but I am doing the following: Every button to build a structure is actually a custom UMG widget with a variable type that references the class that all my buildings inherit from. So when this custom widget is added to a parent widget (either manually in the designer or in code/blueprint function), I set the type to the blueprint class that I want to build with this widget. The widget also has an event dispatcher, that is called when the button in the widget is clicked and that passed the building class as a parameter to the event listener. Additionally, I use an asset reference variable type in my building blueprint to select a texture that is present as an icon on the build button. When the widget is created, the asset reference is retrieved via the ‘get class defaults node’ and then loaded asynchronously and set as the image for the icon in the widget.

It looks like this: http://blueprintue.com/blueprint/_akiszg6/

When I have a new building type, I can add a new widget of this type to the menu and set the blueprint class reference in the widget. It could be more dynamic by adding all these widgets for every building in code when the menu is created, based on an array of building classes set in the parent element or maybe even more automated by using the asset library, but the above way gives control on how the buttons are arranged in the menu (grouped by type etc.).