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
0ctipusPrime
2 years agoExplorer
For those who struggled to follow the solution like me:
1. Pick one of the prepared ITransformers that is closest to your vision (eg. OneGrabFreeTransformer, TwoGrabPlaneTransformer). They can be found in the Grabbable folder of the package Meta XR Interaction SDK, but you can just search for them in your project tab in Unity.
2. Create a copy of it into your assets (because you can't modify them in the package)
3. Modify functionality however you see fit.
For example add `GameManager.ObjectSelected(_grabbable.Transform.gameObject);` like me to track which object has been selected. The `_grabbable.Transform.gameObject` is the reference to the object that is grabbed. To make my example with you need to implement event triggering ObjectSelected method in the GameManager. BeginTransform might look like this:
public void BeginTransform()
{
Pose grabPoint = _grabbable.GrabPoints[0];
var targetTransform = _grabbable.Transform;
_grabDeltaInLocalSpace = new Pose(targetTransform.InverseTransformVector(grabPoint.position - targetTransform.position),
Quaternion.Inverse(grabPoint.rotation) * targetTransform.rotation);
GameManager.ObjectSelected(_grabbable.Transform.gameObject);
}
4. Add this new ITransform script to the grabbable object
5. Find Grabbable in the inspector of the GameObject, expand the Optionals and drag the component (that is attached to the same game object from step 4) into the field One (or Two) Grab Transformer.
6. Test whether your changes in the script had an effect.
This is how the object you want to grab might look like.
hannhudd
2 years agoHonored Guest
This was so helpful-- thank you!
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