Solved
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 the player
- when it is unscrewed (dis-engaged), it SHOULD be grabbable by the player
My understanding is the boolean attribute "allowOffhandGrab" can / should be used for this, however this attribute is only read-only in OVRGrabbable.cs.
Adding a setter in OVRGrabbable.cs has not had any effect on disabling OVRGrabbable during runtime.
As a partial workaround solution, I've also tried enabling / disabling the game object's collider and rigidbody.detection components. Both of these work by allowing me to toggle the object's "grabbability" however creates interactivity issues with other game objects, so is not a feasible solution.
Can someone please help?
Thank you.
As an example, a virtual "screw":
- when it is screwed into a hole (engaged), it SHOULD NOT be grabbable by the player
- when it is unscrewed (dis-engaged), it SHOULD be grabbable by the player
My understanding is the boolean attribute "allowOffhandGrab" can / should be used for this, however this attribute is only read-only in OVRGrabbable.cs.
Adding a setter in OVRGrabbable.cs has not had any effect on disabling OVRGrabbable during runtime.
/// <summary>
/// If true, the object can currently be grabbed.
/// </summary>
public bool allowOffhandGrab
{
get { return m_allowOffhandGrab; }
set { m_allowOffhandGrab = value; } // Added to test grabbablity switching (ie. on / off) but does not seem to work
}
As a partial workaround solution, I've also tried enabling / disabling the game object's collider and rigidbody.detection components. Both of these work by allowing me to toggle the object's "grabbability" however creates interactivity issues with other game objects, so is not a feasible solution.
Can someone please help?
Thank you.
