Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Question Instantiate an object and force it to be grab

Discussion in 'XR Interaction Toolkit and Input' started by raitoryuukuu, Feb 9, 2021.

  1. raitoryuukuu

    raitoryuukuu

    Joined:
    Jan 21, 2020
    Posts:
    7
    hi.
    I have an issue, i would like to instantiate an object at a point (exactly i would like to instantiate a copy of the object i just trow into the hand as "grabbed state" so it can be trow away without having to instantiate somewhere and have to grab it manually.

    i tried to look inside the whole code to try something but i didn"t succeed to make anything close to force a grab state into my object.

    Thank you in advance for everyone who will try to help me on this.
     
  2. raitoryuukuu

    raitoryuukuu

    Joined:
    Jan 21, 2020
    Posts:
    7
    i found forceSelect but i can't make this work so i'm not sure i try to use the right thing

    i tried this way :


    public XRInteractionManager interactionManager;
    public XRGrabInteractable grabInteractable;
    public XRDirectInteractor directInteractor;
    public void AutoGrab()
    {

    interactionManager.ForceSelect(directInteractor, grabInteractable);

    }

    But TBH i have no idea where to put the XRInteractionManager script, on what object ?
     
    Last edited: Feb 9, 2021
  3. FusionPlay_Timo

    FusionPlay_Timo

    Joined:
    Dec 1, 2020
    Posts:
    8
    Hi, you can use ForceSelect in the XRInteractionManager like:

    Code (CSharp):
    1. var copyObject = Instantiate(YourObject);
    2. XRInteractionManager.ForceSelect(interactor, copyObject)
    The XRInteractionManager should something like a Singelton in the World or you can use you XRGrabInteractable.interactionManager
     
  4. raitoryuukuu

    raitoryuukuu

    Joined:
    Jan 21, 2020
    Posts:
    7
    Thank you.

    I have this issue with your method : An object reference is required for the non-static field, method, or property 'XRInteractionManager.ForceSelect(XRBaseInteractor, XRBaseInteractable)'

    i succed to make it work by puting an XRInteractionManager. on a random object and doing this :




    Code (CSharp):
    1.  
    2.             itCopy = Instantiate(itCopy);
    3.             XRInteractionManager.ForceSelect(directInteractor, itCopy.GetComponent<XRGrabInteractable>());
    so when i trow my item it does copy it into my hand but the problem is that it copy it everyframe until i push the grip button making infinite copy in few seconds i tryed with bool pass to true with onselect enter but onselect enter seams to work when we push the grab button so it doesn"t change a thing.

    i managed to make it copy only every trow but the balls doenst get grab anyway....
     
    Last edited: Feb 9, 2021