I’m new to Unity and purchased a set of modular building pieces from the asset store. I’m trying to arrange pieces of wall. The pieces are 5 x 5 x 0.5, so I’ve set my world grid size to 5 units and am using align to grid to make them line up nicely. I’m running into an issue when I try to make a corner. When I align the pieces to the grid, there is some gap and overlap, as seen in this picture:
I then tried to manually move the end piece inwards, which resulted in this:
That looks slightly better, but needed a manual adjustment so I don’t think doing this everywhere scales very well, and plus there is some kind of visual/lighting artifact where the pieces overlap (hard to see in the screenshot but very obvious when I move around in game mode). Then I tried resetting that end piece back to the grid and pushing the two side pieces inwards, which resulted in this:
This looks good and has no overlap, but required a bit of manual adjustment and brought the sides off of the grid.
Assuming a set of wall pieces that are 5x5x0.5, how can I configure my grid and snap settings so that everything fits together nicely?
I think you’re finding that what you want to do is mathematically impossible, since the walls have thickness. A “square” room can’t be a square with the pieces you have, unless you overlap them, in which case things will look bad from certain angles.
What you probably need is just a “corner”, which would probably be 0.5 x 5 x 0.5, and you’d place those in all corners. That would result in a 6x6 room, if you made the smallest possible room with those pieces.
I also personally don’t like objects whose centers snap to grids. I almost always prefer if some outer corner snap to grip. In your case, your center line of the wall is aligned with the grid. I’d probably make a new prefab, simply placing the existing Wall prefab inside of it, and placing it .25 units in some direction, so that you can align the corner of the wall to the grid.
I was thinking the same thing (at least for “structural” objects). An alternative to parenting the prefab to an empty object and offsetting would be to use Probuilder (or an external 3D modeling tool) to set the pivot point of your mesh to one of the corners.
Thank you!! That makes sense. I looked and it turns out this set does have “corner” pieces, but they aren’t just a 0.5x0.5x0.5 corner that I could drop in to what I screenshotted above, but more of a rounded version of the 5x5x0.5 wall.
If you were placing the wall inside a new prefab and pushing it 0.25 units in some direction, would you do it so that the entire 0.5 thickness is inside the grid or outside the grid? It seems like if you did “inside” you’d still have overlap, and if you did “outside” you’d still need corner pieces, is that right? And is there a way to do this new prefab technique that scales well if you wanted to do it to a whole bunch of existing prefabs? I’m imaging it would take me a long time, but maybe with practice you get more efficient I guess.
Thanks! I’m not familiar with Probuilder. If I’m pretty new to Unity, should I learn how to do things without that tool first or does it make sense to jump right in to using it?
One thing to say, first of all, is that no matter how you set up your prefabs, you’re likely to run into some problems in some edge cases, no matter how you do it. So, just be aware that you’ll probably end up in a few cases where you need to compromise rather than having the perfect solution in all cases.
As for whether the volume of the object is “inside” or “outside” the grid, I don’t think that’s really a sensible question. It will be both “inside” and “outside”, depending on how you rotate the object. Here’s a simple wall made in ProBuilder, aligned to a 1x1 grid:
The idea of not centering the objects doesn’t resolve the corner issue. You’ll still have exactly the same problem as you did before: Corners either overlap, or they leave a huge empty spot on the corners. But it does mean it leaves clean spaces for the corners to eventually be placed in. It depends on the usage, but I’d generally build the prefabs so that the volume of the wall is outside the enclosed area. Here’s the start of a 4x4 room:
Now, make a “corner” prefab to snap into those empty corners, and it should be simple enough to finish up this room:
You might also consider creating larger building blocks out of your work. What I mean is after you are satisfied with a room, you turn the entire room into a prefab. Make several variations, and then you can quickly place entire rooms instead of fiddling with each individual wall. You can then make relatively minor tweaks with your spare time so they don’t all look identical, instead of spending all your time just building more and more rooms. You could extend that idea to entire buildings, or whatever else you might construct.