microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Script that implements IInputClickHandler is invoked multiple times with Dev_Unity_2017.2.0 branch #868

Closed qmatteoq closed 6 years ago

qmatteoq commented 7 years ago

Hello, I've created a while ago a very simple app for HoloLens: you tap in the air and it creates a prefab in front of you, which then falls down and collides with the objects in the room thanks to Spatial Mapping. Now I'm trying to port this application to Mixed Reality in order to support both HoloLens and immersive headsets, so I did the following steps:

  1. I've installed the latest Windows Insider build in the Fast Ring
  2. I've installed the latest Windows 10 SDK
  3. I've installed Unity Beta 2017.2.06b
  4. In my original Unity project, I've removed from the Assets folder the old version of the HoloToolkit and I've replaced it with the one from the Dev_Unity_2017.2.0 branch
  5. I've removed the HoloCamera from the project and replaced it with the MixedRealityCameraParent one

I didn't change anything related to how I've implemented the prefab creation with air tap. In the InputManager prefab in the scene I have a custom script, which implements the IInputClickHandler interface. Then, in the OnInputClicked() method, I just create a new instance of the prefab:

public void OnInputClicked(InputClickedEventData eventData)
{
    var instance = Instantiate(Prefab);
    instance.gameObject.transform.position = GazeManager.Instance.GazeOrigin + GazeManager.Instance.GazeNormal * 1.5f;
    WorldAnchorManager.Instance.AttachAnchor(instance.gameObject, Guid.NewGuid().ToString());
}

However, since I've ported the app to the new toolkit, when I execute the action (either with the gesture on the HoloLens or by pressing the joypad button on an immersive headset or in the Unity editor), my script isn't invoked anymore just once but four times. The result is quite easy to see: the prefab is created 4 times and, if I place a breakpoint in Visual Studio in the OnInputClicked() method and I choose to launch the app in the Unity editor, I can see the breakpoint being hit 4 times.

Am I doing something wrong or is there any breaking change I'm not aware of? Thanks!

StephenHodgson commented 7 years ago

Currently the 2017.2 Dev branch is very behind the master. Try pulling the master merge to 2017.2 and test this. Thanks.

SimonDarksideJ commented 6 years ago

Is this still an issue post merge @StephenHodgson ? or can it now be closed

StephenHodgson commented 6 years ago

Needs to be tested and confirmed with master merge.