HoloLens: Adding Fallback Input Handlers for Positioning Out-of-Sight Objects

The TapToPlace  script of the HoloToolkit is a great and simple way to place and anchor holograms in the real world. However, it can be problematic if the hologram is placed out of reach / view from a previous session in another room and you can not tap the hologram to place it closer to you once again.

A good solution is to create another “reset” gesture that triggers object placement even if you don’t directly tap the hologram. An easy way to achieve this is the tap-and-hold gesture, which is one of the standard events the Input Manager of the HoloToolkit can send.

To handle interaction events that don’t target a particular hologram, the current HoloToolkit uses Fallback Input Handlers. However, this functionality isn’t very well documented anywhere. This guide explains how to write a custom fallback input handler.

Handling Fallback Input Events

For the general setup: first, ensure that your Unity HoloLens project includes the InputManager  Prefab from the HoloToolkit. Next, add the standard TapToPlace  script of the HoloToolkit to the game object you want to place in the world.

Now, add the following script HoldAnywhereHandler  to your scene, for example also into the Managers game objects hierarchy where you have placed the InputManager  prefab.

The script will register itself as the fallback input handler for any hold events that the user performs while not looking at a hologram. Accessing the input manager instance of the HoloToolkit works using the singleton pattern.

In this case, we are only interested in the event when the hold gesture has been completed: OnHoldCompleted . Whenever we get this, we simulate the click event for the pre-configured target object. We do not need to send any event parameters, as the standard TapToPlace  script does not use the parameters. In order to not accidentally ending the placement, we only send the click event if the hologram is not already being placed.

Script Configuration

The only final step is to assign the target hologram that we want to place. To do this, drag the placeable game object (that has the TapToPlace  script assigned) to the configuration section of the new HoldAnyhwereHandler  script.

As a result, you can tap and hold anywhere in the world to start placement of the hologram. You don’t need to hit the object anymore with your tap gesture as required by the default TapToPlace  script of the HoloToolkit.

  • pranav gadamsetty

    Hi,

    I have been successful in using your script in addition to TapToPlace script to place a hologram wherever I want to in the physical environment. However, I’m not able to get out of the “placing” mode. Basically, when I perform a hold task i’m able to move the hologram but how i do i place it at a certain position. I have gone through the script and i haven’t found any method to stop “isBeingPlaced”. I have also tried to modify the script to achieve my purpose but i’m not able to get it done. Could you please help me with this.

    Thanks,
    Pranav Gadamsetty

    • Andreas Jakl

      The custom script actually only triggers the placement mode of a target object when you tap-and-hold anywhere. This seems to work fine for you.

      The rest of the placement is then handled by the TapToPlace script of the HoloToolkit. Essentially, that script will get out of the “isBeingPlaced” on a normal single tap onto the object – and as the object is always under your cursor, it should receive that tap event.

      In your case, it looks as if the target game object doesn’t get the tap event so that the mode never ends. Does it work to start the placement through a single-tap onto the object? Could it be that you don’t have a (box) collider on the object you’re placing? Or that there is some other object /collider inbetween you and the object you want to place?

      • pranav gadamsetty

        Hi

        Thanks for the early reply. The placement doesn’t work with a single-tap onto the object. The object does have a collider on it because I have a script that scales up any object by 1.1 times when the gaze focuses on it. So I can say for sure that the object is hit by the Raycast. But, when i air tap once it is in the “placing”, the bool doesn’t change back to false.

        Thanks,
        Pranav Gadamsetty

        • Andreas Jakl

          Ok – that means that you are also not able to place the object successfully without the additional “HoldAnywhereHandler”? -> same situation if you just start placement by tapping on the GameObject through the HoloToolkit “TapToPlace” script?

          I’d suggest placing a breakpoint / debug output in OnInputClicked() of TapToPlace to see if that method is being called at all.

          If that method isn’t called, go one level up in the hierarchy. Check the InputManager script of the HoloToolkit and analyze that.

          First check RaiseInputClicked() / HandleEvent() to see if that gets the click event and where it’s going to. Could be that you have an OverrideFocusedObject defined, or if the GazeManager doesn’t register that it’s hitting the gameobject you’d like to place. Which will in turn reveal if your event is sent to another gameobject or if no game object is found at all (which could hint at issues with the collider, distances, …)

          • pranav gadamsetty

            Hi,

            Thanks for that reply. Yes, I’m not able to place the object without using “HoldAnywhereHandler” script. I couldn’t figure out what the problem is. But, I did find a workaround.

            Instead of using if (IsBeingPlaced) in the Hold event to reverse the bool, I used else{ }. I don’t know why, but it started working. Ideally, it should work in both cases since both of them represent the same condition but, for some reason the latter one is working and the former one is not.

            Anyways, thanks for you help.

            Pranav Gadamsetty

          • Andreas Jakl

            Excellent, great to hear you got it working!