Toggle Snapping in Build System

I’m very new to Unreal Engine and I’ve been following some tutorials for a building system. I have snapping but I want the ability to turn snapping off while I am holding a button.

Personally I’d try to put it somewhere other than this function. It looks like you’re doing the line trace (or whatever you’ve used) outside.

Make sure you have your input set up already. You say you want it to turn off when you’re holding a button, but I’d bet you’d probably want the opposite. If you do actually want that, just flip these values:

If you want it to be a toggle rather than hold system, you can instead use a flip flop node:



For the check itself, I’d recommend something like this:

We simply check after doing whatever would normally lead to a snap (as a stand-in I’m using a line trace node)- if we should snap. If we should, we continue with how you’ve mostly done before. If we shouldn’t snap, we just set our snap transform variable to be wherever the mouse is (assuming you’re placing the building with your mouse). After that, you can just continue with whatever you were doing before, but use the SnapTransform variable instead of dragging right off of detect build boxes.

Thanks for the response! I ended up figuring it out last night after staring at it for long enough, the solution I found was incredibly similar to what you recommended (but way less efficient so I will probably implement your solution to clean things up). Now I’m having another semi-related issue that you may be able to help with. The snapping is turning off and working great, but the line trace is still interacting with the collision boxes used to detect the snapping. Is there someway I can override the collision presets when snapping is false?

For further clarification, here is an image of what I mean. The trace is picking up on the collision allowing me to place a wall in mid-air.

I will say I’d highly recommend condensing those 6 trace channels into 1 called snappables or something. If you’re trying to place a painting or something, but are only tracing walls, you’d be able to place them through the floor. Same with a couch through a wall or something. You can do a simple check to see if what you collided with was snappable (ie check if it was a wall / floor). You can only have 18 custom channels (including trace and object), so I think you should try to avoid using 6 for snapping.
image

I’m not quite sure how you have your system set up. Could you maybe clarify that? While I’m sure I can help you, I’m not sure why you have a snapping point mid-air…

I hope this clarifies a little. I’ll use my foundations as an example, I have 8 separate box collisions (4 for walls, 4 for foundations as pictured) that I’m using to detect whether an object snaps or not. What I believe is happening is when I turn of snapping, the trace channel is still detecting these box collisions and allowing me to place them on the invisible collision boxes.

So I think the easiest workaround for this would be to use a select node to switch trace channels whenever you’re snapping.

Don’t worry- though it looks like an integer, what the select node prompts you to give for an index is a wildcard. You can just drag the bool pin directly to it.
image

Great, seems pretty straightforward. Thanks for all your help, I really appreciate it!