Snapping allows the user to quickly position GameObjects in specific ways relative to other GameObjects by dragging them close to each other. For GameObjects to be able to snap together, the user has to create SnappableObjects for each GameObject, describing how they should snap to other GameObjects.
An example of two conveyors snapping together
There are several different SnappableObject that describe how GameObjects should snap with each other.
Basic Snappable Objects
There are three basic Snappable Objects. Each of these have their own set of rule on how to snap to other SnappableObjects. Each of these SnappableObject only handle positioning of a GameObject during snapping.
You can find all of these Snappable Objects in the “Add Component” menu.
All Snappable Objects have the following basic settings.
The “direction of flow” of the SnappableObject. SnappableObjects can be set to one of the following three I/O’s:
Depending on the combination of I/O’s between SnappableObjects, they can or cannot snap together.
Whether this SnappableObject enforces a certain direction onto SnappableObjects that with it.
The forward direction of the SnappableObject that is applied when Directional is enabled. Two SnappableObjects are placed together so that their forward directions are facing towards each other.
Connected Snappable Objects
A list of all Snappable Objects that the Snappable Object currently is snapped to.
How to use
Have a GameObject you want to be able to snap to other GameObjects.
Create Snappable Objects for it as required. Make sure to have these parented under the GameObject.
Drag the GameObject closer towards other GameObject with Snappable Objects and snapping will automatically be enabled. A thether will be drawn indicating which Snappable Object will snap together upon releasing the mouse button.
Snapping can be disabled from the Scene View. In the top left corner of the Scene View you can find the “Enable Snapping” button. By default, this will be enabled. Clicking this button once will disable Snapping for all Snappable Objects. Clicking it again will re-enable Snapping. Holding Alt on the keyboard will temporarily disable Snapping.
Snappable Objects of the SnappablePoint type will have icons indicating whether they are currently snapped, unsnapped, or whether there is currently something wrong with its setup.
The icons in the image below provide with some information about the SnappablePoint.
From left to right:
A “blank” dot means that this SnappablePoint is correctly setup and unsnapped.
A dot with a Check-mark means that this SnappablePoint is correctly setup and snapped to another Snappable Object.
A dot with an exclamation mark means that there is currently something wrong with the setup of the SnappablePoint. This can happen both when snapped or unsnapped.
Secondary snapping allows Snappable Object that “happen to align” as a result of another snap, to also snap together. The snapping system uses a set margin to both position and angle to determine whether a given Snappable Object applies for Secondary Snapping. Settings for both can be found in the Snapping Settings window. Here are a few examples in which case Secondary Snapping can be very useful:
Snapping a Line to multiple Points
Snapping multiple Snappable Objects under a single parent
The Snapping Settings window can be accessed through the context menu of any Snappable Object. This will open a separate window in which you can set various settings.
Where to access the Snapping Settings window
Snapping Settings window layout
The relative maximum length of the tether that is drawn during snapping in the editor.
The maximum allowed distance between points in meters in order to apply for Secondary Snapping.
The maximum allowed angle between points in degrees in order to apply for Secondary Snapping.
Clicking this button will reset all these settings to their default values.