SOLVED

MRTK Question: How to end a grab interaction via code?

%3CLINGO-SUB%20id%3D%22lingo-sub-2238235%22%20slang%3D%22en-US%22%3EMRTK%20Question%3A%20How%20to%20end%20a%20grab%20interaction%20via%20code%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2238235%22%20slang%3D%22en-US%22%3E%3CP%3EI've%20been%20searching%20through%20the%20documentation%20and%20experimenting%20with%20several%20approaches%2C%20but%20I%20haven't%20been%20able%20to%20find%20an%20easy%20way%20to%20accomplish%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESay%20you%20have%20a%20cube%20with%20all%20of%20the%20script%20components%20attached%20to%20allow%20the%20user%20to%20grab%20the%20cube%20with%20either%20hand%20and%20move%20it%20around%20(%3CEM%3EBox%20Collider%2C%20NearInteractionGrabbable%2C%20Object%20Manipulator)%3C%2FEM%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20would%20you%20go%20about%20forcing%20the%20user%20to%20let%20go%20via%20code%3F%20Let's%20assume%20you've%20set%20a%20new%20Vector3%20to%20the%20transform%20position%20on%20the%20cube%20to%20teleport%20the%20cube%20back%20to%20its%20starting%20location.%20%3CSTRONG%3EHow%20do%20you%20properly%20end%20the%20grab%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20happens%20is%20that%20after%20changing%20the%20cube's%20position%20in%20code%20it%20flys%20back%20into%20the%20user's%20pinched%20fingers%20like%20they%20have%20Jedi%20powers%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fhtml%2F%40C7BE33135EA1742D4E0CF1FF00DD009F%2Fimages%2Femoticons%2Fcryingwhilelaughing_anim.gif%22%20alt%3D%22%3Acryingwithlaughter%3A%22%20title%3D%22%3Acryingwithlaughter%3A%22%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20two%20approaches%20so%20far%20to%20force%20the%20hand%20tracking%20to%20just%20let%20it%20go%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EDisabling%20the%26nbsp%3B%3CEM%3ENearInteractionGrabbable%26nbsp%3B%3C%2FEM%3Eand%26nbsp%3B%3CEM%3EObject%20Manipulator%3C%2FEM%3E%20script%20components%20on%20the%20cube%20and%20then%20re-enabling%20them.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%3CLI%3EChanging%20the%26nbsp%3B%3CEM%3EManipulation%20Type%26nbsp%3B%3C%2FEM%3Eproperty%20on%20the%26nbsp%3B%3CEM%3EObject%20Manipulator%3C%2FEM%3E%20to%26nbsp%3B%3CEM%3Enone%20(0).%3C%2FEM%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%2C%20the%20moment%20you%20either%20re-enable%20them%20or%20set%20the%20%3CEM%3EManipulationType%26nbsp%3B%3C%2FEM%3Eback%20to%20One%20and%20Two%20Handed...%20Force%20powers%20kick%20in%20and%20the%20cube%20flys%20back%20into%20your%20fingers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20assuming%20this%20is%20because%20both%20the%20disabling%2Fre-enabling%20or%20setting%20to%20none%2Fsetting%20back%20to%20both%20hands%20is%20occuring%20within%20the%20same%20frame.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20the%20next%20thing%20I'm%20going%20to%20try%20is%20creating%20an%20action%20queue%20so%20that%20the%20re-enablement%20step%20(or%20setting%26nbsp%3B%3CEM%3EManipulationType%3C%2FEM%3E%20back%20to%20both%20hands)%20occurs%20in%20the%20next%20frame.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20thoughts%20though%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20some%20simple%20%3CEM%3Erelease()%3C%2FEM%3E%20method%20that%20I'm%20overlooking%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2239245%22%20slang%3D%22en-US%22%3ERe%3A%20MRTK%20Question%3A%20How%20to%20end%20a%20grab%20interaction%20via%20code%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2239245%22%20slang%3D%22en-US%22%3EWell...%20none%20of%20that%20worked.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20think%20I'll%20try%20just%20destroying%20the%20game%20object%20and%20instantiating%20a%20new%20one%20back%20in%20its%20starting%20location.%3C%2FLINGO-BODY%3E
Occasional Contributor

I've been searching through the documentation and experimenting with several approaches, but I haven't been able to find an easy way to accomplish this.

 

Say you have a cube with all of the script components attached to allow the user to grab the cube with either hand and move it around (Box Collider, NearInteractionGrabbable, Object Manipulator).

 

How would you go about forcing the user to let go via code? Let's assume you've set a new Vector3 to the transform position on the cube to teleport the cube back to its starting location. How do you properly end the grab?

 

What happens is that after changing the cube's position in code it flys back into the user's pinched fingers like they have Jedi powers :cryingwithlaughter:

 

I've tried two approaches so far to force the hand tracking to just let it go:

 

  1. Disabling the NearInteractionGrabbable and Object Manipulator script components on the cube and then re-enabling them.

  2. Changing the Manipulation Type property on the Object Manipulator to none (0).

 

The problem is, the moment you either re-enable them or set the ManipulationType back to One and Two Handed... Force powers kick in and the cube flys back into your fingers.

 

I'm assuming this is because both the disabling/re-enabling or setting to none/setting back to both hands is occuring within the same frame.

 

So, the next thing I'm going to try is creating an action queue so that the re-enablement step (or setting ManipulationType back to both hands) occurs in the next frame.

 

Any thoughts though? 

 

Is there some simple release() method that I'm overlooking?

1 Reply
best response confirmed by Toryn Farr (Occasional Contributor)
Solution
Well... none of that worked.

I think I'll try just destroying the game object and instantiating a new one back in its starting location.