Forum Discussion

rex.gatling.963's avatar
2 months ago

Grabbable Events

I need an event to happen when the player grabs the object using the Grabbable component. I don't see that option on the script nor is it accesible. How can i do this? 

2 Replies

  • You likely want to use the `InteractableUnityEventWrapper` component. You can then wire up the `Select` (grab) and `Unselect` events.

    Drag your Intractable/Interaction view in the editor, and it will prompt you if you want it for Hand or Controller interactions.

     

  • Hi rex.gatling.963,

    Electrobeer's answer is the correct one if you want to wire it to every GrabInteractable in your object.

    If, alternatively, you want to directly get this from the Grabbable.cs you can do something like: 

    ```
    public Grabbable myGrabbable;

    void OnEnable()
    {
        myGrabbable.WhenPointerEventRaised += HandlePointerEventRaised;
    }

    void HandlePointerEventRaised(PointerEvent evt)
    {
        if (evt.Type == PointerEventType.Select)
        {
            // Do Something
        }
    }
    ```

    or create your own component similar to  InteractableUnityEventWrapper.cs if you want to expose it as a UnityEvent and wire it in the Inspector.


→ Find helpful resources to begin your development journey in Getting Started

→ Get the latest information about HorizonOS development in News & Announcements.

→ Access Start program mentor videos and share knowledge, tutorials, and videos in Community Resources.

→ Get support or provide help in Questions & Discussions.

→ Show off your work in What I’m Building to get feedback and find playtesters.

→ Looking for documentation?  Developer Docs

→ Looking for account support?  Support Center

→ Looking for the previous forum?  Forum Archive

→ Looking to join the Start program? Apply here.

 

Recent Discussions