Perazim
Perazim

Reputation: 1529

Why 'Is Kinematics' works different on HoloLens?

Overview
I wanted to have a cube, that I can drag around the scene with the components Collider, Rigidbody and ObjectManipulator. In play mode everything works fine, but running it on the hololens, the cube starts flying around after dragging it a few time.

Steps to reproduce (All components are set via editor, not via code)

  1. Create new project and set it up for AR/HoloLens
  2. Import MRTK 2.4
  3. Create cube with a Box Collider. Set Is Trigger = true
  4. Add Rigidbody to cube. Set Use Gravity = false and Is Kinematic = true
  5. Add Object Manipulator to cube. I have a method getting called after On Manipulation Ended, but don't know if thats important.

Expected behavior
The rigidbody is set to Is Kinematic = true and Use Gravity = false, so that the cube stays still/stops moving after releasing dragging it. This works while trying it inside the unity play mode. But running it on the hololens, the cube behaves like Is Kinematic = false and starts flying around after interacting with it. Sometimes after the second drag and sometimes after the third time drag.

Error
Before updating this post, I didnt noticed the development console in left corner of my hololens. At the beginng of the scene I get the message [Physics.PhysX] BV4 midphase only supported on intel platforms but at that moment everything is fine. As the cube begins to fly around I get the a NullReferenceExeption: Object reference not set to an instance of an object.

Upvotes: 0

Views: 389

Answers (1)

Perazim
Perazim

Reputation: 1529

I fixed my issue. I know the approximate cause, but I do not fully understand it. The method, getting called after OnManipulationEnded caused that.

  1. I have a list, getting filled and drained by OnTriggerEnter/-Exit (exit looks the same, except add→remove):

     private void OnTriggerEnter(Collider other){
     if (other.gameObject.layer != 31) return;
     _objectsCollidingWith.Add(other.gameObject);}
    
  2. OnManipulationEnded triggered this method:

     private int GetMeshes(List<KeyValuePair<Transform, Mesh>> transMeshes){
     foreach (GameObject go in _objectsCollidingWith)
     {
         transMeshes.Add(new KeyValuePair<Transform, Mesh>(go.transform , go.GetComponent<MeshFilter>().mesh));
     }
     return transMeshes.Count;}
    

So I got alot of nullreferences from GetMeshes, because some gameobject in the list _objectsCollidingWith were null. Thats because the mesh is getting updated every once in a while. That caused a lot of nullreferences until the cube just flew away.
I used the whole time the logging provider via the device portal and couldnt see what is causing this errors. But after running the project via holographic emulation I could see in the console where they were coming from.

How did I fixed my problem?
I found this post because I realized that my OnTriggerExit didn't get called and cased having null objects and some spatial meshes with the same name triggered OnTriggerEnter very often. Also I added this line in the foreach loop in GetMeshes because once in a while there is still a null object:

if (go == null)
  continue;

PS: Please forgive the strange code formatting, somehow the editor here on so does not allow me to place the brackets somewhere else

Upvotes: 0

Related Questions