Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Trigger Colliders lead to graphical glitches (Unity)

ChrigiChrigi
edited April 2017 in Questions And Answers

Hello

I wanted to create different capsule colliders so that when I walk to a certain position I could trigger an event.
Setting it up worked fine (capsule collider on the camera with a rigid body and a trigger capsule collider on the object) but when using it, I get extreme glitches:

  • The position of the holograms jitters when walking around
  • The position is very unstable when I stand in the reach of the trigger collider
  • When I stand in the trigger collider the colors of the object in front of me starts to drift apart, come back together and drift apart again.
  • When I walk very near to the problematic object, the issues get better but don't completely vanish

All of this is only visible on the display, the mixed reality capture does not show any of this.

Did I setup something wrong? What could cause this?

Best Answers

  • thebanjomaticthebanjomatic ✭✭✭
    Answer ✓

    @Chrigi This sort of thing often happens when setting the stabilization plane to be too close to the camera. I'm assuming that you are using the input manager and cursors from the holotoolkit which sets the stabilization plane for you based on a raycast. What is likely happening is that your trigger collider is being hit by the raycast, and returning a point that is too close to the camera.

    You can prevent trigger colliders from participating in raycasts, with the following setting:
    Edit > Project Settings > Physics > Uncheck "Queries Hit Triggers"

  • ChrigiChrigi
    edited May 2017 Answer ✓

    @stepan_stulov @mark_grossnickle
    I finally figured out what was going wrong with the triggering. Oh man... I set it up exactly as I discussed above. In the editor it works fine, so it has to do with something not available in the editor: The Spatial Map

    The events are fired by the spatial map which intersects the trigger area with the isTrigger = true collider.
    I created a new Physics Layer and assigned it to the camera and the trigger area and made sure this layer only interacts with each other but I had the Spatial Mapping Prefab as a child of the camera. Moving it out into my manager object fixed it :) it works now as intended!

    (So the title of this subject is a bit wrong. The color separation and jitter was because the stabilization plane was automatically set to the trigger collider and when walking through the plane the glitches occured. The sporadic and repeated triggering was caused by the trigger collider interacting with the spatial map)

Answers

  • The jitters, unstable, and shifting all sounds like performance issues. Have you run the profiler and checked how your performance is? Or draw calls/verts for gpu performance?

    Taqtile

  • @mark_grossnickle said:
    The jitters, unstable, and shifting all sounds like performance issues. Have you run the profiler and checked how your performance is? Or draw calls/verts for gpu performance?

    Thanks for your reply. I did some more analysis on this. It does not seem to be a clear performance Issue. The FPS is a solid 60 all the time so I don't think that is the problem.

    In my minimal test case now I did not notice the jitters anymore and the position was fine but I could still notice the strange color drifting sometimes when entering/exiting the trigger area.

    I think something is seriously wrong with my triggers. When inside the collider the events behave as expected but after leaving the collider it constantly throws the OnTriggerEnter & OnTriggerLeave events instead of just throwing OnTriggerLeave once.

  • thebanjomaticthebanjomatic ✭✭✭
    Answer ✓

    @Chrigi This sort of thing often happens when setting the stabilization plane to be too close to the camera. I'm assuming that you are using the input manager and cursors from the holotoolkit which sets the stabilization plane for you based on a raycast. What is likely happening is that your trigger collider is being hit by the raycast, and returning a point that is too close to the camera.

    You can prevent trigger colliders from participating in raycasts, with the following setting:
    Edit > Project Settings > Physics > Uncheck "Queries Hit Triggers"

  • Screenshot of your triggers with colliders showing?

    Taqtile

  • Hm, so when I select "Draw Gizmos" on the Stabilization Plane script I see that the plane is not too close but just to be sure I deselected "Queries Hit Triggers". Thanks for the tip.

    At the moment I have not seen the color separation anymore.

    I have made a couple of screenshots: https://imgur.com/a/DgW0p
    Here is the HotspotTrigger script: https://dl.dropboxusercontent.com/u/2836/HotspotTrigger.cs

    I am absolutely lost regarding the Triggers. The Events trigger at random and when I shake my head at any distance, the trigger events are thrown.

    I'm sorry this is not directly related to the topic title but nevertheless extremely frustrating.

  • Why does your camera have a collider and rigid body on it? Since the camera is your head in Hololens you won't want those on it as it should move around freely without physics constraints.

    Taqtile

  • Because I want my physical location to be able to trigger an event.

  • hmm. You don't want a rigid body on there though as you shouldn't change a rigid body's position manually (which the camera would change). You could keep the trigger on it though. Try removing the rigid body and see if that fixes your issue.

    Taqtile

  • stepan_stulovstepan_stulov ✭✭✭
    edited May 2017

    Hey, @mark_grossnickle, @Chrigi

    Firstly, as far as I know, OnTriggerEnter() and OnTriggerExit() both require a Rigidbody to be present otherwise they won't be called. There is no way around it. The terminology of Unity, if simplified, is that Colliders are sort of shapes that something can bump into (isTrigger = false) or enter (isTrigger = true) while Rigidbodies are agents that are being moved by physics and bump into or enter Colliders. Themselves having their boundaries defined by their own Colliders. The very wording of the methods OnTriggerEnter() and OnTriggerExit() implies something is entering and something is being entered. Anyway, this is getting philosophical. From Unity docs:

    Notes: Trigger events are only sent if one of the colliders also has a rigidbody attached.

    Secondly one shouldn't change the position and rotation of a Rigidbody manually only when that Rigidbody's isKinematic property is set to false, because such would cause conflict of authority and all kinds of "physically impossible" situations. Setting that property to true frees your hands as that Rigidbody is now uninvolved into physics at all and is safely ready for changes from within a script or an animation or even dragging by the gizmo in the Scene View. Triggers will still work though. isKinematic is probably the property causing the problem.

    If, still, unwanted collisions are the problem it seems that disabling intersections in the Project Settings -> Physics -> Layer Collision Matrix would solve unwanted inter-layer interaction. You will generally want to cleanup all the colliders that are automatically added when creating primitives and design your collision layers matrix to know exactly who collides with whom. I would simply create a layer Walking, untick its involvement with all other layers and set it for the human body (under camera) and for the landmarks.

    Building the future of holographic navigation. We're hiring.

  • @stepan_stulov Thanks for the extensive explanation.

    I will check the Layer Collision Matrix and will try to optimize it so only the correct layers interact. But I have to make sure that the Raycast of the Stabilization Plane will still interact with the correct colliders. I think you can specify these interactions using Tags. I will check that. Thank you!

    Sadly it's still not 100% clear to me how to set up my use case: Execute OnTrigger on Object when camera moves into it's collider.

    What I understand:

    isTrigger = true -> Sends the OnTriggerEnter/Stay/Exit events when a rigidbody enters the collider (https://docs.unity3d.com/ScriptReference/Collider-isTrigger.html)

    OnTriggerEnter -> Will be sent to the trigger collider and the rigidbody that touches it (https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html)

    isKinematic = true -> You can freely move the rigidbody around. If it would be false, only forces were allowed to move it around (https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html)

    There is thing I'm still not sure about: isTrigger specifies "when a rigidbody enters the collider" which would imply that I would want the following situation:

    Camera:
    Collider with isTrigger = false
    Rigidbody with isKinematic = true (I want to be able to re-position it)

    Trigger Area:
    Collider with isTrigger = true
    Script with the OnTriggerEnter/Exit functions

    Would this be correct? Or should the Collider & Rigidbody be exactly the other way around? Another setting for isKinematic?

    As I want to be able to move the camera and the hotspot location around I would always have to set isKinematic = true as I otherwise would not be able to change the position.

  • I would like to add that I have a scene where many objects have a collider on them but I don't have any collider or trigger on my camera and the exact same glitches happens.
    It does raycast on every update in order to show the cursor but I don't know if it's related.
    I'll try "Edit > Project Settings > Physics > Uncheck "Queries Hit Triggers" suggested by @thebanjomatic , although I find such behaviour rather strange especially since @Chrigi said the mixed reality capture was fine.

  • stepan_stulovstepan_stulov ✭✭✭
    edited May 2017

    @Chrigi

    I will check the Layer Collision Matrix and will try to optimize it so only the correct layers interact. But I have to make sure that the Raycast of the Stabilization Plane will still interact with the correct colliders. I think you can specify these interactions using Tags. I will check that. Thank you!

    Not sure what you mean by that. Stabilization plane has nothing to do with physics at all. You just specify where you want HoloLens to focus its resources for rendering and stabilization. There may be no colliders at that point at all.

    Would this be correct?

    Yes. basically the enteree should be isTrigger=true while for the enterer it's not important, can be any. But it's leave it to false since it's you entering the landmark, not the landmark entering you. Both the enterer and the enteree get their OnTriggerEnter and OnTriggerExit called with the opposite side's collider being passed as an argument which is convenient for all kinds of tag or name checks. Note that OnTriggerEnter and OnTriggerExit methods have to be defined in a component that's attached to the game object of either the enterer or the enteree or both. If you just specify it somewhere else it won't be called. It's only called on the participants.

    One thing is sure what you want is achievable without weird bouncing against sptial mapping collider.

    Again, make sure you don't have unplanned colliders that are often added when creating primitives. Just search for "t:Collider" in the Hierarchy View. You may be surprised to how many colliders there are you didn't think exist. Next make sure the enteree has a trigger collider and the enterer has a non-trigger collider and a kinematic rigidbody. And finally cleanup layers.

    Building the future of holographic navigation. We're hiring.

  • @stepan_stulov
    Okay thank you very much I will it using this setup again.

    Not sure what you mean by that. Stabilization plane has nothing to do with physics at all.

    What I mean is that if you use the InputManager from the HoloToolkit it will use the StabilizationPlaneModifier script to automatically set the plane to a reasonable location. For this it uses the GazeManager script which in turn will perform a Raycast to determine the currently gazed at Hologram. This only works if the Hologram has a collider for the Raycast to hit.
    The important thing here is that this Raycast only interacts with the colliders you want it to. If configured wrong it could set the plane so that you can walk through it or it's set too close to the camera, leading to the mentioned glitches. @Adurnat maybe this is your problem.

  • @Chrigi Indeed I tried with the checkbox "Set Stabilization Plane" unchecked and there aren't any color separation anymore. Although now the stabilization plane is disabled but it's less of a problem. Thank you !

  • @Adurnat
    If you want to enable it make sure that the Gaze Manager only interacts with the collider you want. You can set the "Draw Gizmos" Button on the Stabilization Plane script and then it will show you in the editor when you press play where it positions the plane.

  • @Chrigi I need to have mesh colliders on all the objects in my scene, but I unchecked the checkbox "Use Gaze Manager" and it worked like a charm. "Draw Gizmo" helped a lot, thanks for the tip.

  • ChrigiChrigi
    edited May 2017 Answer ✓

    @stepan_stulov @mark_grossnickle
    I finally figured out what was going wrong with the triggering. Oh man... I set it up exactly as I discussed above. In the editor it works fine, so it has to do with something not available in the editor: The Spatial Map

    The events are fired by the spatial map which intersects the trigger area with the isTrigger = true collider.
    I created a new Physics Layer and assigned it to the camera and the trigger area and made sure this layer only interacts with each other but I had the Spatial Mapping Prefab as a child of the camera. Moving it out into my manager object fixed it :) it works now as intended!

    (So the title of this subject is a bit wrong. The color separation and jitter was because the stabilization plane was automatically set to the trigger collider and when walking through the plane the glitches occured. The sporadic and repeated triggering was caused by the trigger collider interacting with the spatial map)

  • @Adurnat You can keep the plane and the Gaze Manager. Just create a new physics layer (e.g. "stabilization") and set the collider where you want to put the plane to this layer. Then make sure that the Gaze Manager only interacts with this layer by selecting it in the dropdown. You just have to make sure that the user can NOT walk through the point where you set the plane because that's when the glitches happen.

Sign In or Register to comment.