[SOLVED] - Unity VR - I want that the Object knows when it is being grabbed

Hello my fellow Unity enthusiasts,

I am trying to activate the gravity of an Object when it is grabbed and I would like to do that via a script that the object itsself has.


This means I want the Object to detect, that it is being grabbed and not the Controller recognizing that it is grabbing something and then have to get the Object the Controller is holding.


When the Object recognizes it is being grabbed I want to execute the following line of code:

gameObject.transform.parent.gameObject.GetComponent<Rigidbody>().useGravity = true;

Don’t worry about the parent thing, I have disabled the box that makes the hand a parent automaticaly.
If you need any further information feel free to ask, I will provide you with everything you may need.

Again I found the answer myself, why always after I posted the questions and not in the hours before during research? I don’t know.


Anyways the solution, even if a little bit different from what I wanted, was quite simple. There is a script called “Interactable Hover Events”, which is part of the Steam VR Package, in which you can define actions that shall happen upon hover begin/end and upon attach begin/end.


This means I simply had to attach said script to the Object and select an action for the event I wanted. It even came with prepared actions I could choose from, no extra code or self written action needed.


Hopefully this helps someone else one day, since it took me ages to find, even though it is so simple, or maybe because of that.