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

[OVR] Forcing a grabbed object to be dropped

Discussion in 'Scripting' started by Jwako, Jun 25, 2020.

  1. Jwako

    Jwako

    Joined:
    May 22, 2019
    Posts:
    8
    I'm trying to make a scene transition where the player would grab an object and that would trigger the game to begin loading a different scene. The problem is that i'd ideally want to make that object disappear before the scene transitions and i'm scared that letting the player keep holding the object through the scene transition would introduce some weird interaction with the grabber script or something. An easy solution to this would seem to be to force the object to be dropped before the transition, but just calling the GrabEnd() function of the Grabbable has already shot me in the foot in previous attempts of something similar.

    How would i force the player to drop the object without breaking something in the scripts?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,958
    This is completely unanswerable because nobody here knows how you shot yourself in the foot.

    Use source control, make changes you want, test them, if your foot develops a hole, revert them, or else aim the gun away from your toes.
     
    lordofduct likes this.
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,384
    Depends on your implementation?

    We don't know what "GrabEnd" or "Grabbale" is. Where did you get this code? Did you write it yourself? If so wouldn't you know the best approach? If not, or you don't know, maybe share the code here to give us an idea of your implementation?
     
  4. Jwako

    Jwako

    Joined:
    May 22, 2019
    Posts:
    8
    I'm sorry, i'm using the Oculus Integration packet thats free on the asset store, i thought thats what everyone who works with OVR is using.
     
  5. sharramon

    sharramon

    Joined:
    Nov 11, 2018
    Posts:
    4
    Oh hi, a bit late but I ran into the same problem and thought to answer for prosperity.

    Go into OVRGrabbable and make m_grabbedBy public

    Then add this script to the grabbable object. I made it so that you turn off OVRGrabbable. I don't really know if it's needed, but it was an extra precaution just in case there was any weird case in the middle where the object could be 'regrabbed'.


    public class Destroy : MonoBehaviour
    {
    private OVRGrabber myGrabber;
    public void destroyThis()
    {
    //this turns off the OVRGrabbable script
    this.GetComponent<OVRGrabbable>().enabled = false;
    //this gets the hand that's grabbing it
    myGrabber = this.GetComponent<OVRGrabbable>().m_grabbedBy;
    //use ForceRelease method in the OVRGrabber to release object
    myGrabber.ForceRelease(this.gameObject.GetComponent<OVRGrabbable>());
    //destroy object
    Destroy(this.gameObject);
    }
    }


    You can't just destroy the object I've found, or unity will get very mad at you and throw you errors b/c the script keeps trying to parent the grabbed object (which is null) to the grabber.

    Then just call this method from the scene transition script, probably through something like

    YourGameObject.GetComponent<Destroy>().destroyThis();
     
    Jwako likes this.