Immerse SDK
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Snap Target

A Snap Target is what a Snapper snaps to, making it a child in the hierarchy. The Snap Target is also decides which Snapper is allowed to snap to it via the Requirements list (see below)

SnapTarget component as it appears in the Inspector

Requirements

Requirements are what restrict which Snappers are allowed to snap to it. A Snap Target with no requirements will allow any Snapper to snap to it.

Add

To add a requirement to a Snap Target:

  1. Expand the Requirements array if not already
  2. Click the ‘Add Requirement’ button
  3. Select the desired requirement from the menu

Remove

To remove a requirement from a Snap Target:

  1. Expand the Requirements array if not already
  2. Right click the requirement to be removed
  3. Select ‘Delete Array Element’
Snap Target requirements are processed in the order they appear in the list

Custom Requirements

A number of commonly used requirements are included with the SDK including an ‘Allow List’, ‘Block List’ and ‘Max Angle’ (which only allows snapping within a limited rotation range).

Creating your own requirements is easy. Simply create a Serializable class that inherits the ISnapRequirement interface. Once created, it will automatically be added to the ‘Add Requirements’ menu.

Below is the implementation for the included Allow List requirement:

/// <summary>
/// A list of allowed Snappers for a SnapTarget
/// </summary>
[Serializable]
public class AllowList : ISnapRequirement
{
  	/// <summary>
  	/// Allowed snappers for this target
  	/// </summary>
  	/// <remarks>If this list is left empty, all Snappers will be accepted</remarks>
  	[Tooltip("Allowed snappers for this target")]
  	public List<Snapper> Allowed = new List<Snapper>();

  	/// <summary>
  	/// Check if requirements are met
  	/// </summary>
  	/// <param name="snapper">Snapper</param>
  	/// <param name="snapTarget">Snap Target</param>
  	/// <returns>Returns true if the Snapper meets the SnapTarget's requirements</returns>
  	public bool IsAllowed(Snapper snapper, SnapTarget snapTarget)
  	{
	  	return Allowed.Contains(snapper);
  	}
}

Events

Snap Targets provide events that can be used for triggering gameplay logic in an experience.

Event Description
On Snap Triggered when a Snapper is snapped to the Snap Target
On Unsnap Triggered when a Snapper is unsnapped from the Snap Target
On Hover Enter Triggered when a valid Snapper is held near the Snap Target
On Hover Exit Triggered when a previously valid Snapper leaves the snapping range of the Snap Target