Example¶
The following steps demonstrate one possible setup for using the snap functionality in a game.
Add the Grid Actor¶
- Create a project by selecting the third person template.
- Open the project.
- Go to the Place Actor tab and search for the Central Grid actor.
- Drag the actor into your world and set the grid visuals to true.
Add the function¶
- Open the character blueprint or any other blueprint you wish to place the logic into.
- Create a reference to the Central Grid actor.
- Drag out from the actor reference and search for the Get Snap Parameter function.
- Create a reference to the Camera Component and connect it to the Target Object pin.
- Set the Snap Type to Highest Corner.
- Tick all Snap to checkboxes.
- Split the Lock pin and create the three boolean variables named Lock X-Axis, Lock Y-Axis and Lock Z-Axis and connect them to the corresponding Lock pin. Alternatively you can right click the pins and promote them to a variable.
- Split the OUT pin and promote the Snap Location to a variable.
Hook up events¶
- In this example we use the Left Ctrl, Left Shift and Left Alt key to toggle the boolean variables.
- To use the snap location, simply facilitate the built-in Unreal Engine Spawn Actor function to spawn any actor at the snap location. In this example we use the Left Mouse Button to execute.