Forum Discussion
jaumet2000
4 years agoHonored Guest
Check if an object is grabbed
Hello guys. I can't find a way to check if an object is grabbed or not, a boolean that is true if it is grabbed and false if it is not. The attached image is the components that the object that I w...
- 4 years ago
There might be an easier solution but when I did this, I also wanted a few other features so I created my own ITransformer and put it in the Grabbable Script. Once you do this, you can just copy-paste the code in the default ITransformer you want. In an ITransformer, there is a method called BeginTransform() that is called when an object is first grabbed and EndTransform() when it is unselected. I'd recommend saving a bool somewhere else that is changed by these methods.
EDIT: If you want to get the gameobject inside the iTransformer script use this (assuming the script is on the gameobject):
_grabbable.Transform.gameObject
sirtario9
2 years agoHonored Guest
Hey!
I had a similar problem, I just want to share my solution.
This was made with Meta SDK v65 and Unity 2022.3.12f1
How it works:
Oculus Interactions works with 4 states that both the interactors and interactables have. https://developer.oculus.com/documentation/unity/unity-isdk-interactor-interactable-lifecycle/
If you have an Object you want to grab, you can add the Grab Interaction via the new Quick-Actions feature. This will add a Child GameObject that holds all the Grab scripts Oculus needs and set up a rigid body if not already present. You can then simply get the current state of an Interactor or Interactable via the e.g.:
GrabInteractable.State
Using this
I then wrote a script that one can attach to the GameObject.
The script itself is used to snap two GameObjects together. for this to happen I needed to detect if a GameObject was let go. it holds the last state and gets the current state to detect the state change. The script assumes that the GrabInteractable is attached to the Generated Child GameObject.
//get States for detecting if Brick has been let go
LastState = CurrentState;
CurrentState = GetComponentInChildren<Oculus.Interaction.GrabInteractable>().State;
//detect if grabbed brick is let go
// Select => currently grabbed
// Normal/Hover => not grabbed
if (LastState == Oculus.Interaction.InteractableState.Select &&
(CurrentState == Oculus.Interaction.InteractableState.Normal
|| CurrentState == Oculus.Interaction.InteractableState.Hover))
{
DetermineSnapKind();
}Scene Graph for good measure.
- volo.volo12 months agoHonored Guest
Hello,
I have tried your solution and written a following script:using System.Collections; using System.Collections.Generic; using UnityEngine; using Oculus.Interaction; public class GrabDetection : MonoBehaviour { private GrabInteractable _grabInteractable; // Start is called before the first frame update void Start() { _grabInteractable = GetComponentInChildren<GrabInteractable>(); if (_grabInteractable == null) { Debug.LogError("GrabInteractable component not found in children."); return; } } // Update is called once per frame void Update() { if (_grabInteractable == null) { return; } var currentState = _grabInteractable.State; Debug.Log("Current state: " + currentState); if (currentState == InteractableState.Normal) { Debug.Log("Current state: OBJECT NOT GRABBED"); } if (currentState == InteractableState.Select) { Debug.Log("Current state: OBJECT GRABBED"); } } }
I am grabbing an object but select does not get there. Console just keeps printing "Current state: normal". Do you have an idea what could I check?
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
- 2 years ago
- 8 years agoAnonymous