Search Unity

  1. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice
  3. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  4. Dismiss Notice

Place object into the hand of the player by script

Discussion in 'AR/VR (XR) Discussion' started by Verdemis, Apr 22, 2020.

  1. Verdemis

    Verdemis

    Joined:
    Apr 27, 2013
    Posts:
    90
    Hello everyone,

    I'm working with the Unity XR Interactor Toolkit. I'm trying to figure out if there is a way to place an object in the players hand by script. What I'm trying to do is... there is a trigger collider and when a player places a hand inside this trigger and he uses the grip button I would like to instantiate a XR Grab Interactable game object which is placed in the players hand, like if he had grabbed an object in the scene.

    Has anyone an idea how I could make this?

    Best,
    Verdemis
     
    aaroniousdesigns likes this.
  2. hptware

    hptware

    Joined:
    Dec 11, 2012
    Posts:
    107
    Hi Verdemis,

    I came across your unanswered question whilst looking for a solution to my own problem. I was doing something similar. Placing an object in an inventory slot on my player character by releasing the grip whilst the hand was in the slot trigger. Destroying the object. Then instantiating the object when the hand was in the inventory slot trigger and putting it in the players hand.

    The only insight I can give is attaching an interactable occurs on grip press, thus the object will not stay in the players hand unless the grip is pressed moments after instantiating it. My solution was to have a lower press threshold for the grip press to instantiate the object, then use an X ray interactor with a sphere cast to grab the object. Does that help?

    Best,
    Matt
     
    aaroniousdesigns and hessex like this.
  3. aaroniousdesigns

    aaroniousdesigns

    Joined:
    May 6, 2017
    Posts:
    1
    Identical situation here. I'm thinking a possibility could include "equipping" the weapon by instantiating as a child of the hand, outside of the XR Grab system altogether. We could watch controller input actions so that if the select/grip is released, the weapon detaches itself (and drops to the floor), or we just Destroy it and Instantiate a new grab-ready one in it's place (which again, drops to the floor, ready to grab again).

    That's more of a hack than a solution. Sure there's a way to Instantiate as grabbed, or programmatically create and grab. Hoping for a proper solution!
     
  4. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    367
    You could look into the XR toolkit code and see what the grab button actually does to grab the object, but I think calling ForceSelect on the InteractionManager should work for your case, instantiate the object, place it where you want and then call ForceSelect with your controller and the grab object as parameter
     
  5. AnthonyJackson81

    AnthonyJackson81

    Joined:
    May 30, 2019
    Posts:
    25
    hello. I am weirdly trying to use ForceSelect this afternoon..... Cannot seem to get it working. Have you tried this?

    I have no errors and I feel as I have set this up. Its not my first time extending or inheriting a class, but it is my first time trying to convince the interaction manager I need to ForceSelect an object.
     
  6. pixelfilm

    pixelfilm

    Joined:
    Feb 15, 2021
    Posts:
    8
    I have the same issue.
     
  7. AnthonyJackson81

    AnthonyJackson81

    Joined:
    May 30, 2019
    Posts:
    25
    I just killed the feature, just did it differently. Frustrating, but I've learnt with alot of 'released' stuff from Unity it rarely works first time, I dont have spare time to behunting down methods that dont work . AR Foundation is the same right now. If I had more spare time Id look at Unreal Engine, at there have been some really impressive experiences producted on that platform.
     
  8. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    367
    The XR Toolkit is still in preview to be fair, I also noticed an annoying bug that wasted me several hours, but XRInteractionManager ForceSelect works fine for me, it calls SelectEnter which is the same method that would be called if you grab a object with the select button (grip by default).

    You can't hold multiple objects with the same controller at the same time, are you sure that the controller is "empty" before you call the select method?
     
    AnthonyJackson81 likes this.
unityunity