The 'SetVertexSnapTargetObjects' Function

In order to support vertex snapping in your application, you need to inform the move gizmo about the objects which contain the source vertices. You do this via a call to SetVertexSnapTargetObjects which belongs to the MoveGizmo behaviour.

The following code creates an object move gizmo and the uses the 'SetVertexSnapTargetObjects' to specify the objects that will be used to gather the source vertices:

// Create an object move gizmo and set its target object
ObjectTransformGizmo objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
objectMoveGizmo.SetTargetObject(targetObject);

// Access the move gizmo behaviour and specify the vertex snap target objects
MoveGizmo moveGizmo = objectMoveGizmo.Gizmo.MoveGizmo;
moveGizmo.SetVertexSnapTargetObjects(new List<GameObject>{ targetObject });

Note

It is important that the vertex snap target objects be the same as the target object specified via a call to SetTargetObject.

With this code, you can run the app and when pressing V and moving the mouse, the move gizmo will pick the object vertex which is closest to the mouse cursor position. When dragging the mouse, the target object will be snapped to other object verts or to the grid cell points.

Note

When using the SetTargetObject (singular), you will need to call SetVertexSnapTargetObjects every time the target object changes.

When using the SetTargetObjects (plural) function, you pass the same object collection to the SetVertexSnapTargetObjects function:

// Create an object move gizmo and set its target object
ObjectTransformGizmo objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
objectMoveGizmo.SetTargetObjects(targetObjectCollection);

// Access the move gizmo behaviour and specify the vertex snap target objects
MoveGizmo moveGizmo = objectMoveGizmo.Gizmo.MoveGizmo;
moveGizmo.SetVertexSnapTargetObjects(targetObjectCollection);

Note

When using the SetTargetObjects (plural), you only need to call SetVertexSnapTargetObjects once at initialization.

Enabling & Disabling Vertex Snapping

You can enable or disable vertex snapping by calling the SetVertexSnapEnabled function:

MoveGizmo moveGizmo = objectMoveGizmo.Gizmo.MoveGizmo;
moveGizmo.SetVertexSnapEnabled(isEnabled);