Interaction Events

Configure Logic to Fire the Weapon on Player Input

Jordan T Kay
3 min readApr 30, 2024

A pistol is no use to anyone if it cant fire anything, and luckily for us the XR GRAB INTERACTABLE includes Interactable Events.

WHAT ARE INTERACTABLE EVENTS?
Interactable events are Unity Events that can apply to Interactables — allowing programmers to easily configure logic based on player input.

EVENT TYPES

There are several events defined within the XR Grab Interactable that we can subscribe our custom functions to, thus allowing us to have something happen depending on what the player is doing. These events are…

HOVER

There are several different events that we can subscribe functions too which will be called during different hover states…

  • HOVER ENTERED — Event is called when an interactor (controller) begins to hover over the interactable
  • HOVER EXIT ED— Event is called when an interactor (controller) ends hovering over the interactable
  • FIRST HOVER ENTERED — Event is called ONLY when the first interactor begins hovering over the interactable. If another interactor begins to hover while the first interactor is still hovering, the event is not called.
  • LAST HOVER EXITED — Similar too First Hover Enter, event is called ONLY when the last remaining interactor ends hovering over the interactable.

SELECT

There are several different events that we can subscribe functions to which will be called during different select states…

  • SELECT ENTERED — Event is called when an interactor (controller) begins selecting the interactable
  • SELECT EXITED — Event is called when an interactor (controller) ends selecting the interactable
  • FIRST SELECT ENTERED — Similar to First Hover Entered Event is called ONLY when the first interactor begins to select the interactable. If another interactor begins to select the interactable the event will not be called as long as other interactors are still selecting it
  • LAST SELECT EXITED — Similar to Last Hover Exited Event is called ONLY when the last remaining interactor ends selecting the interactable

ACTIVATION STATUS

Not to be confused with activating/deactivating the Interactable GameObject (GameObject.SetActive).

  • ACTIVATED — Event is called when the interactor activates the interactable, such as from a trigger pull on the controller
  • DEACTIVATED — Event is called when the interactor deactivates the interactable, such as from the release of the trigger on the controller

GUN FIRE LOGIC

To create the gunfire logic, we must use the INTERACTABLE EVENT ACTIVATED.

Within the activated event we need to subscribe a method held within the pistol controller script.

TEST

--

--

Jordan T Kay

Join my journey into game development with Unity. Learning all I can to produce quality games. 🚀