Forum Discussion
DeakinCUBE
6 years agoExplorer
How can I toggle (enable / disable) OVRGrabbable on a Unity game object in script?
I would like to toggle OVRGrabbale on a game object, subject to a boolean condition. As an example, a virtual "screw": - when it is screwed into a hole (engaged), it SHOULD NOT be grabbable by t...
- 6 years agoI've managed to solve it...turns out it was very easy but requires changes to OVRGrabbable.cs and OVRGrabber.cs
For anyone else who comes across this problem:
Step 1)
In OVRGrabbable.cs
public bool allowOffhandGrab{get { return m_allowOffhandGrab; }set { m_allowOffhandGrab = value; } // Add this line to allow write-access to attribute}
Step 2)
In OVRGrabber.cs:protected virtual void GrabBegin(){float closestMagSq = float.MaxValue;OVRGrabbable closestGrabbable = null;Collider closestGrabbableCollider = null;// Iterate grab candidates and find the closest grabbable candidateforeach (OVRGrabbable grabbable in m_grabCandidates.Keys){//bool canGrab = !(grabbable.isGrabbed && !grabbable.allowOffhandGrab); // was thisbool canGrab = !grabbable.isGrabbed && grabbable.allowOffhandGrab; // change to thisif (!canGrab){continue;}
Step 3)
Now you can toggle OVRGrabbable on/off in script by referencing the OVRGrabbable script and then setting "allowOffHandGrab" to true (can grab) or false (cannot grab)
Eg:public class Screw : MonoBehaviour{private OVRGrabbable _OVRGrabbable;private void Awake(){_OVRGrabbable = GetComponent<OVRGrabbable>();}
public void ToggleGrab(bool value)
{
_OVRGrabbable.allowOffhandGrab = value; // True = can grab; False = cannot grab
}
}
Hope this helps anyone else who encounters this problem.
:-)
juruhn
6 years agoExplorer
Hi DeakinCUBE,
Due to time pressure, I made a workaround.
As I exactly know when they need to be grabable and not, I just add and remove the OVRGrabbable script to the object.
There were a few updates by now, so maybe the issue is fixed. Haven't tested it yet.
Happy to hear others experiences with the OVRGrabbable.
Due to time pressure, I made a workaround.
As I exactly know when they need to be grabable and not, I just add and remove the OVRGrabbable script to the object.
There were a few updates by now, so maybe the issue is fixed. Haven't tested it yet.
Happy to hear others experiences with the OVRGrabbable.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 7 months ago