I am following the scene understanding docs to get a scene understanding mesh. Here's my code, init
is triggered when a click on a box with the pointer.
I get a COMException
with error code -2147024891
, which apparently is some access denied error. You can see where I catch the exception.
using Microsoft.MixedReality.SceneUnderstanding;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class StartSceneUnderstanding : MonoBehaviour
{
// Start is called before the first frame update
async void Start()
{
if (!SceneObserver.IsSupported()) {
Debug.Log("Huh. SceneObserver isn't supported.");
}
SceneObserverAccessStatus accessStatus = await SceneObserver.RequestAccessAsync();
Debug.Log($"Access status: {accessStatus}");
}
// Update is called once per frame
void Update()
{
}
public void Init() {
Debug.Log("Initializing scene understanding");
// Create Query settings for the scene update
SceneQuerySettings querySettings;
querySettings.EnableSceneObjectQuads = true; // Requests that the scene updates quads.
querySettings.EnableSceneObjectMeshes = true; // Requests that the scene updates watertight mesh data.
querySettings.EnableOnlyObservedSceneObjects = false; // Do not explicitly turn off quad inference.
querySettings.EnableWorldMesh = true; // Requests a static version of the spatial mapping mesh.
querySettings.RequestedMeshLevelOfDetail = SceneMeshLevelOfDetail.Fine; // Requests the finest LOD of the static spatial mapping mesh.
// Initialize a new Scene
var x = SceneObserver.ComputeAsync(querySettings, 10.0f);
var awaiter = SceneObserver.ComputeAsync(querySettings, 10.0f).GetAwaiter();
try {
Scene myScene = awaiter.GetResult();
} catch (COMException e) {
Debug.Log($"Failed to construct scene. Error code {e.ErrorCode}. Message:\n{e.Message}");
var a = 1;
}
}
}
The problem is SceneObserverAccessStatus accessStatus = await SceneObserver.RequestAccessAsync();
. I moved it to the Init
function, and the error went away.