2023.1.116.1 Copy of Using the "new" snapping system
The new snapping system works with MonoBehaviours that describe snapping behaviour. To make a GameObject snappable, it needs a Snappable Object monobehaviour assigned to it.
Opposed to the “old” system, there is no SnappingController present in the scene/hierarchy. This is run as a static class in the background and oversees snapping automatically.
Types of Snappable Objects
There are three base types op Snappable Objects.
Snappable Points
Snappable Lines
Snappable Splines
All three objects inherit from a shared base component (SnappableObject) which describes how to hook onto the snapping system. These have been split because the mathematics behinds these objects on how to find the best snap is different for all three of them. All snapping behaviour (currently) required can be built from these three base components.
Current Snappable Objects built from the base objects:
Snappable In/Output
Snappable Action Cue
These objects both have “extra” behaviour and/or conditions to them regarding snapping with other Snappable Objects.
How to use the new Snapping objects
To make a GameObject “snappable”, add the required snapping objects to the GameObject.
Move the GameObject from the scene closer to other Snappable Objects and when in range, a tether will be drawn.
Once you release the mouse while this tether is drawn, the objects snaps accordingly.
All Snappable Objects can have a specific snap direction set. This is represented by a yellow arrow gizmo. This indicates the direction the object will face when snapping onto another snappable object. If at least one of both objects had Directional
enables, direction will be taken into account. Otherwise, no rotation will be applied when snapping.
Snappable Object specific Settings
Snappable Point
Describes a point in the world that can be snapped to. Accepts a maximum of one snap. Can snap with Points, Lines and Splines.
Field |
|
---|---|
Snapping Properties | This shows the properties that Snappable Objects share by default. |
I/O | Whether this Snappable Object marks an In- or Output of an Asset. Inputs cannot snap to other Inputs. Output cannot snap to other Outputs. Any other combination is allowed to snap with each other. |
Directional | When this is enabled, the direction in which an objects is facing when a snap is applied, matters for this Snappable Object. For example, a Conveyor needs to align its end to a receiving module. If it were to connect at a 90 degree angle, Product transfers would not go smoothly. |
Direction | The direction that this Snappable Object uses to determine rotation during snapping. The direction of the two snapping objects will be placed so that there are pointing towards each other. |
Connected Snappable Objects | If this object is currently snapped to any other Snappable Objects, those objects will be shown here. |
Snappable Line
Describes a lines in the world that can be snapped to. Accepts any number of snaps. Can only snap with Points.
Field |
|
---|---|
General Settings | These are settings specific to the Snappable Line. |
From | The local point from which the Snappable Line starts. |
To | The local point at which the Snappable Line ends. |
Snapping Properties | This shows the properties that Snappable Objects share by default. |
I/O | Whether this Snappable Object marks an In- or Output of an Asset. Inputs cannot snap to other Inputs. Output cannot snap to other Outputs. Any other combination is allowed to snap with each other. |
Directional | When this is enabled, the direction in which an objects is facing when a snap is applied, matters for this Snappable Object. For example, a Conveyor needs to align its end to a receiving module. If it were to connect at a 90 degree angle, Product transfers would not go smoothly. |
Direction | The direction that this Snappable Object uses to determine rotation during snapping. The direction of the two snapping objects will be placed so that there are pointing towards each other. |
Connected Snappable Objects | If this object is currently snapped to any other Snappable Objects, those objects will be shown here. |
Snappable Spline
Enabled snapping for a Spline. Accepts any number of snaps. Can only snap with Points.
Field |
|
---|---|
General Settings | These are settings specific to the Snappable Spline. |
Spline | The spline for which snapping will be enabled. |
Snapping Properties | This shows the properties that Snappable Objects share by default. |
I/O | Whether this Snappable Object marks an In- or Output of an Asset. Inputs cannot snap to other Inputs. Output cannot snap to other Outputs. Any other combination is allowed to snap with each other. |
Directional | When this is enabled, the direction in which an objects is facing when a snap is applied, matters for this Snappable Object. For example, a Conveyor needs to align its end to a receiving module. If it were to connect at a 90 degree angle, Product transfers would not go smoothly. |
Direction | The direction that this Snappable Object uses to determine rotation during snapping. The direction of the two snapping objects will be placed so that there are pointing towards each other. |
Connected Snappable Objects | If this object is currently snapped to any other Snappable Objects, those objects will be shown here. |
Snappable InOutput
Describes a point in the world that can be snapped to. Accepts a maximum of one snap. Can snap with Points, Lines and Splines. If it snaps to another Snappable InOutput, a Junction will automatically be created between the two. If no Spline has been assigned, this object will not be eligible for snapping.
Field |
|
---|---|
General Settings | These are settings specific to the Snappable InOutput. |
Spline | The spline for a Junction will be created when snapping. |
Junction | A reference to the created Junction. |
I/O | Whether this Snappable Object marks an In- or Output of an Asset. Inputs cannot snap to other Inputs. Output cannot snap to other Outputs. Any other combination is allowed to snap with each other. |
Directional | When this is enabled, the direction in which an objects is facing when a snap is applied, matters for this Snappable Object. For example, a Conveyor needs to align its end to a receiving module. If it were to connect at a 90 degree angle, Product transfers would not go smoothly. |
Direction | The direction that this Snappable Object uses to determine rotation during snapping. The direction of the two snapping objects will be placed so that there are pointing towards each other. |
Connected Snappable Objects | If this object is currently snapped to any other Snappable Objects, those objects will be shown here. |
Snappable Action Cue
Describes a point in the world that can snap to Snappable Splines only. Accepts a maximum of one snap. If it snaps to a SnappableSpline, the Action Cue will be automatically parented and assigned to that Spline. If no Action Cue has been assigned, this object will not be eligible for snapping.
Field |
|
---|---|
General Settings | These are settings specific to the Snappable Action Cue |
Action Cue | The Action Cue that will be assigned to the Spline that this object snaps to. |
I/O | Whether this Snappable Object marks an In- or Output of an Asset. Inputs cannot snap to other Inputs. Output cannot snap to other Outputs. Any other combination is allowed to snap with each other. |
Directional | When this is enabled, the direction in which an objects is facing when a snap is applied, matters for this Snappable Object. For example, a Conveyor needs to align its end to a receiving module. If it were to connect at a 90 degree angle, Product transfers would not go smoothly. |
Direction | The direction that this Snappable Object uses to determine rotation during snapping. The direction of the two snapping objects will be placed so that there are pointing towards each other. |
Connected Snappable Objects | If this object is currently snapped to any other Snappable Objects, those objects will be shown here. |
Using the new “SnapController”
Just like the old system, there is a managing component that oversees snapping. This is no longer a component visible in your Scene / Hierarchy, but a static class that runs in the background.
Snapping can still be enabled/disabled, just like in the old system. A similar button for this is available from the Scene View. Clicking this button will enable (red) or disable (grey) snapping. When disabled, snapping will not be active and no snapping gizmos will be drawn. You can also temporarily disable snapping by holding Alt
while dragging objects.
SnapController Gizmos
The new SnapController draws two types of gizmos.
The “Tether”
When dragging objects in your scene, if they are eligible for snapping, and Snappable Objects are moved within snapping range, a tether will be drawn. This indicates which two points on the objects will be snapped to each other. When releasing the mouse button while this tether is being drawn, the indicated snap will be applied. If you hold Alt
while releasing the mouse, no snapping will be applied.
Icons for snap points
Snap points will have extra icons drawn in the scene, indicating their snapping availability. There are two icons, one for a snap point that has not been snapped to anything, and one for a snap point that has been snapped.
Prespective Documentation