Adding/Removing StaticMeshes Setup

Sorry about the maybe somewhat confusing title, but quite frankly I wasn’t entirely sure what to name it.

So I’ll get right to the point; I’m trying to create a block-based building system. Yes, similar to what games like Minecraft, Robocraft and similar games do it. However, my vision is for it to be more similar to that of Robocraft, where the landscape itself will be a regular terrain and not a box/voxel-built one.

So far, I’ve made 2 models for prototyping, a regular box and a sloped box. Currently, I’m stuck at trying to spawn them into the level. I’ve started with a blank project and have set the most common stuff up, and I’ve also made it so whenever “Build Mode” is active, it will do a line trace every tick - getting the location where the player is looking at.

Now my questions are:

1. How do I spawn my static meshes where I am currently pointing my cursor? And what would be the best approach to get proper alignment? So the blocks will snap together? I thought about maybe using Sockets, but then I Would have to make them Skeletal Meshes and I sincerely doubt this is an optimal way of doing things.

2. How would this affect lighting? Will lighting automatically be handled for actors that are spawned after playing has begun?

Edit:

I managed to figure out how to spawn it into the level where I’m looking. So that’s that done. Now there’s just the snapping left… :stuck_out_tongue:

use % (mod) to make it snap.
I think its location - (location % grid size)

Thanks for your reply!

Unfortunately I’m not quite sure as to what you’re talking about :stuck_out_tongue: Couldn’t find any function that seemed relevant.that…

Edit:

Made some progress, the key was in using Impact Normal from the hit result. So I’m half-way there! If anyone else might find it useful, this is how I made it;

Any suggestions on how I should do the Hit Actor check? So I can make sure it only triggers when it hits certain actors?

Edit2:

Here’s a short video I recorded to show how I set it up, and what it’s like ingame. Hopefully some other lost soul out there might find it useful :stuck_out_tongue: If anyone knows of any way to improve upon this, that would be greatly appreciated! :smiley:

There should be a % mod float node or something to that effect. In integer terms it gives you your remainder of a division problem. Take 7/2 = 3.5. The mod is this 7%2 = 1 (1/2 = .5). So you could use this to force even numbers by taking number - (number mod 2) in this case 7 - (7 % 2) = 7 - 1 = 6. That is very similar to snapping and it works for other values besides two. I know floats work a little differently, but I believe it will still work anyway. I’ll double check when I get home.

The attached image resulted in an output of 32 (Which is snapping to 8). The node in question will pop up if you just enter “%” or “mod”. It shows up in the list as % (float). It looks like it was already snapping in your video though.

snapping.png

Thanks for the info! Yeah, I managed to get the snapping to work in the end. Impact Normal yielded the exact results I needed - for example if I hit the front of the box, it would return +1 on the Y axis, if I hit the rear, it would output -1 on the Y axis. This made it very easy to do the rest.

Now I’m just working on how to set up the logic for placing different types of blocks and then I’ll just add rotation and such things. :slight_smile:

This is interesting stuff! I am very new to UE and really have no idea how to do this kind of thing but after seeing/playing robocraft my imagination went crazy with the possibilities of employing such a “building” system which could easily become a “game” in it’s own right. Also, a UE plugin that does this could make level design a lot easier, faster and flexible. Be nice to see a full demo/tutorial of how to go about doing this kind of thing.

How would you go about connecting each piece with a physics constraint?