HoloLens 2 Spatial Mapping Raycast doesn't collide with spatial mesh

Hello everyone,

I am trying to move a sphere around in the HoloLens and if it collides with the spatial mesh it should change it’s color. My problem is that the SphereCast I’m doing to see if it collides with the mesh does not work.

Here is my code for this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SphereCaster : MonoBehaviour
{
    public GameObject currentHitObject;

    public float sphereRadius;
    public float maxDistance;
    public LayerMask layerMask;
    public Transform sphere;

    private float currentHitDistance;

    private Vector3 origin;
    private Vector3 direction;

    // Update is called once per frame
    void Update()
    {
        origin = transform.position;
        direction = transform.forward;
        RaycastHit hit;
        if (Physics.SphereCast(origin, sphereRadius, direction, out hit, maxDistance, layerMask, QueryTriggerInteraction.UseGlobal))
        {
            sphere.transform.gameObject.GetComponent<Renderer>().material.color = Color.red;
            Debug.Log(hit.distance);
            currentHitObject = hit.transform.gameObject;
            currentHitDistance = hit.distance;
        }
        else
        {
            currentHitDistance = maxDistance;
            currentHitObject = null;
            sphere.transform.gameObject.GetComponent<Renderer>().material.color = Color.green;
        }
    }

    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.red;
        Debug.DrawLine(origin, origin + direction * currentHitDistance);
        Gizmos.DrawWireSphere(origin + direction * currentHitDistance, sphereRadius);
    }
}

It works totally fine for GameObjects but I cannot find a way to detect a collision with the spatial mesh. The Sphere I am moving around doesnt have to be stopped or something, it should just change its color.

I hope you can help me out here.
Thanks in advance!

EDIT: The layer I am choosing is the Spatial Awareness layer.
I am using Unity 2019.4.25f1

For those of us who don’t know, what exactly is “the spatial mesh”. Physics queries are designed (unsurprisingly) to detect physics colliders so if the “spatial mesh” is a collider then it’ll work otherwise why would it?

The spatial mesh ist basically a scan of the surface in the room. The HoloLens is capable of scanning your environment and create a mesh out of it.
Now that you said it, it makes sense that it doesnt work. The problem ist that i cannot attach a physics collider to the mesh. Or at least I don’t know how.

What does that mesh object look like in Unity, in terms of like components etc? If for example it’s an object with a MeshRenderer and MeshFilter, then you can add a MeshCollider + rigidbody with isKinematic checked, and it should work.