Ray Interactions
Updated: Oct 7, 2024
What are Ray Interactions?
Ray Interactions enable you to interact with objects in the world from a distance by casting a ray, or line, out from the hand or controller to determine what to interact with. The most common use case for ray interactions is interacting with a user interface to press buttons, drag sliders, etc. Another potential use for ray interactions is to select objects in the world to view information about them, as in a virtual tour, or make changes to them, as in an architectural visualization walkthrough with configurable options for surface materials or lighting conditions.
How do Ray Interactions work?
A Ray Interaction consists of two main elements: an interactor and an interactable. The IsdkRayInteractor lives on the Pawn within the hand or controller rigs. The IsdkRayInteractable is placed on any Actor you want to interact with using a ray interaction. When an IsdkRayInteractor interacts with a IsdkRayInteractable, a Pointer Event is generated with information about the interaction.
To aid in detecting a Ray interaction, another component is required to be placed and configured on the Actor you want to be able to interact with. An IsdkPointablePlane defines the surface that must be intersected to generate the ray interaction.
No visible geometry is technically required for a ray interaction to function; however, the player needs a way to identify an item that can be interacted with. Any visual can be used to represent the interactable item – a simple plane, a user interface, etc.
An IsdkRayInteractor defines the origin and direction of raycasts for a ray interaction, as well as a max distance for the interaction with an IsdkPokeInteractable. There is one IsdkRayInteractor on each of the IsdkHandRigComponentLeft, IsdkHandRigComponentRight, IsdkControllerRigComponentLeft, and IsdkControllerRigComponentRight.
An IsdkRayInteractable represents a ray interactable surface, like a button or a user interface. An IsdkRayeInteractable component must be placed on each item you want to be ray interactable. The IsdkRayInteractable component requires an IsdkPointablePlane to define the surface the ray intersects with. One or more of these should also be added to the item that you want to make interactable.
The basic process to make an item interactable using ray casting is:
- Add an
IsdkRayInteractable component. - Add an
IsdkPointablePlane component. This has a single Vector2 property, Size, which can be set through code or the Blueprint Construction Script or Event Graph. It represents the distance from the centerpoint to the edge on both the X and Y dimensions. The total size of the resulting bounding box of the collider is double the Size. - Set the Size property on the
IsdkPointablePlane to half-size of the collision rectangle. - Set the PointablePlane property on the
IsdkRayInteractable to point to the IsdkPointablePlane component. This can be set through code or the Blueprint Construction Script or Event Graph.
Note: If you are adding ray interaction to a Widget Blueprint, you should use the IsdkInteractableWidget which pre-configures a number of useful settings.
Now that you know how to set up grab interactions with Interaction SDK, continue on to the following guides: