Immerse

ToggleSwitch

Description

A ToggleSwitch is a synchronised interactable switch that does not use Unity physics and has only an "On" and a "Off" state. It users a collider (with no physics) and is synchronised between different users. It is essentially a button but it looks like a switch and will automatically animate using a rotation.

📘

For an overview of how the Immerse SDK deals with interactions, please read the Interaction Overview section.

How It Works

ToggleSwitch uses only a collider (no physics) to enable interaction. When a VR user's hand comes in close proximity to the object, it will automatically change into a pointing state to make pressing easier. The tip of the index finger contains a collider, which will "push" the switch on collision. The switch will automatically animate to "On" or "Off" by a rotation. Once a switch is pressed, a message is sent to all users in a scene.

ToggleSwitch also supports reactions, which allows logic operations to be initiated, when the button is pressed.

How To Implement

  1. Select a new GameObject
  • Reset the Position, Rotation and Scale of the Object. Ensure Position is set to <0, 0, 0>
  • Add ToggleSwitch component
  • Add a child object and then add the Mesh that will rotate as the switch is pressed.
  • Add one or more colliders (BoxCollider is best)
  • Set the Throw (see below)
  • Set the correct Axis (see below)

Common issues

If the switch does not move, or moves unexpectedly:

  • Check the object's resting position and rotation are reset to 0's?
  • Ensure that the correct Axis is being used
  • Check there's a collider on the GameObject - this is necessary for the Immerse SDK to detect engagement and for the Rigidbody to function correctly.
    Note: If a collider is missing, the user's hand will not disappear when the trigger is pulled.
  • Are there duplicate scene indices? Check the Scene Object to find out.
  • Is there a nearby collider which is preventing movement and/or rotation?
  • Check that requirements are set up, and are they all met (they should all be green when in play mode in the Editor Inspector).

A switch that rotates around the X axis

An example of how Switch hierarchy is set up

📘

Immerse SDK Class Library

More detail in ImmerseSDK.Interaction.ToggleSwitch class

Unity Editor Component

Options

PropertyDescription
Verbose Logging Enabled
When enabled, this component instance will log verbosely to the console (only in the Editor). This is useful for debugging, but can have a detrimental effect on the framerate as verbose logging sometimes logs every frame.
IndexThe object's unique index - this will be automatically set by the Immerse SDK and should not be edited.
Allow Interaction only by Local AvatarOnly allows interaction if a Local user or their hand is touching the object
Is Interactable only when parent engagedThis setting is only used when the button is a child of a Pickup. In this case, the button can only be pressed when the Pickup is held in the other hand.
Interaction RequirementsA set of requirements that need to be met to allow interaction; can be used to disable the object until a particular state is reached. See Interaction Requirements for more details.
ThrowThe amount of rotation between "On" and "Off" states around the axis specified in the Axis property
AxisThe axis used for rotation to indicate "On" and "Off" states.

Updated 4 months ago


ToggleSwitch


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.