Changing Controller Grip Button to Trigger

You might want to remap actions or swap the controls in the VR application. As an example, let's do this for the controller. We will remap the Use action from the Trigger to the Grip button, and the Grab action - from Grip to the Trigger.

User input for the controller is defined in the following methods of the VRHandController component (VRHandController.cpp):

  • getControllerButtonPressed(Side side, Buttons button)
  • getControllerButtonDown(Side side, Buttons button)
  • getControllerButtonUp(Side side, Buttons button)

These methods contain a switch statement that maps abstract actions (Buttons::GRAB, Buttons::USE, etc.) to physical buttons. The Buttons enum is defined in VRController.

To swap Grab and Use, swap the bodies of Buttons::GRAB and Buttons::USE cases in all three methods. For example, in getControllerButtonPressed():

VRHandController.cpp

bool VRHandController::getControllerButtonPressed(Side side, Buttons button) const
{
	const InputVRControllerPtr &controller = get_valid_controller(side);
	if (!controller)
		return false;

	switch (button)
	{
	// ... TELEPORT case unchanged ...

	${#HL}$case Buttons::USE:${HL#}$
	${#HL}$	return controller->isButtonPressed(Input::VR_BUTTON_GRIP);${HL#}$
	${#HL}$case Buttons::GRAB:${HL#}$
	${#HL}${${HL#}$
	${#HL}$	int axis_index = controller->findAxisByType(InputVRController::AXIS_TYPE_TRIGGER_VALUE);${HL#}$
	${#HL}$	if (axis_index == -1)${HL#}$
	${#HL}$		axis_index = controller->findAxisByType(InputVRController::AXIS_TYPE_TRIGGER_FORCE);${HL#}$
	${#HL}$	if (axis_index != -1)${HL#}$
	${#HL}$		return controller->getAxis(axis_index) > 0.5f;${HL#}$
	${#HL}$	break;${HL#}$
	${#HL}$}${HL#}$
	case Buttons::MENU:
		return controller->isButtonPressed(Input::VR_BUTTON_APPLICATION)
			|| controller->isButtonPressed(Input::VR_BUTTON_Y);
	case Buttons::INVENTORY:
		return controller->isButtonPressed(Input::VR_BUTTON_X);
	}

	return false;
}
			
Notice
Make sure you update all three methods - getControllerButtonDown, getControllerButtonPressed, and getControllerButtonUp. They must stay in sync, otherwise an action might start on one button and end on another.

Save your changes, then build and run the application by hitting Ctrl + F5 to update component's logic. Close the application after running it and switch to UnigineEditor.

Switch to SDK Browser and launch the application by clicking the Run button on the project's card.

Now you can grab objects by the trigger, and use them by the Grip side button.

The information on this page is valid for UNIGINE 2.22 SDK.

Last update: 2026-09-11 03:51:51