Help with accessing certain points of a spawned grid

I have a grid set up after I followed an unreal tutorial about procedural content. I am just curious if I have a 32x32 grid, what math would be needed to access just the outer layer?
I would like to generate a 3d box with the middle being hollow. I already know how to add the boxes but I am unsure how I can get access to certain points. I can manually pick an index and spawn something there but there’s got to be a math that tells it to choose only boxes on the outside. Anyone have a clue?

Well, it really all depends on what your array looks like. Do you increment the X to 32, then reset x to 1, and increment Y, and then repeat this process? Just tell me what you do in your loop for the indexes and I can tell you the math, and even make a BP for you.

There is no array yet, just following the tutorial.

Alright, are Max X and Max Y both set to 32?

Yea, but I’d like to have it setup that I can adjust those numbers and it know what to do. So I could jump it up to 64x64 and so on. If possible!

Ok, I’ve made you a BP, it should work with any variables when you change them, make sure to count to make sure it’s not off by 1 or 2 instances though:

Basically the break vector should be connected to you final vector that’s going to your add instance, but still keep the original vector for add instance. Pardon me if it doesn’t work, I’m still a bit confused by your algorithm.

I will give it a shot. Thank you much!

With a little bit of tweaking this worked. Thank you!

Alright, could you tell me what you tweaked? I might use something like this in the future. And i’m glad to help :wink:

Instead of dividing it was multiplying.
Also, would you happen to know how you could affect a block once its been generated? I guess minecraft style. I have no idea how to remove these blocks once they are generated

Jackpot for asking that question , I’m actually building a game just like Minecraft, currently, I can place blocks, mine blocks, only the top dirt blocks have grass on them. And yes, you can remove once generated. What I do is I have an array of block locations, array of Block HP, array of block types. When I click on a block, it does a line trace to it, and removes HP, once the HP is gone, it does ‘remove instance’ with the index from the ‘item’ return node on break hit result. The whole world is also randomly generated, I don’t have caves or biomes yet, just dirt world pretty much.

What is your hit result on the line trace? I am confused how to reference the blocks because they don’t have their own BP

Well, I have one ‘Block’ BP, and it makes a bunch of instances, which it looks like you are doing, what you need to do is cast to your CubeSpawn BP, with ‘hit actor’ as your target, and then remove instance using the return value of the cast. I suggest you do all the line tracing and stuff like that in your Character BP. I have all my mining & placing in character, but I also have NEARLY ALL of my variables in my gamemode BP so that I can access them from anywhere.

Alright so I got that working. I can now remove a block on click, but how are you putting the block back? How does the line trace hit it to place it?

Well, this one is quite a bit more difficult. You’ll need to first assign another key to place a block, and then you’ll need to get the hit ‘normal’, using that, you can determine which side of the block you clicked on, and determine the location of where to place the block. I’m not going to give you any example BPs though, because I’ve worked countless hours on my game, and it wouldn’t be very fair for you to know it without figuring it out yourself.

Oh yea man no problem. Thanks for the insight and I will work it out. Good luck on your project!

Yep you too, if you want, you could start working on my game with me, it’ll be going on Steam :slight_smile: If you’re interested, contact info in my signature. Glad I could help.

Appreciate the offer, but I am still new and trying to learn. I will keep an eye out on your progress. Thanks again!