@Ines Yes, you are correct. The endpoint used before was correct and if the data is visible on LUIS portal then i think the AnalyseResponseElements() needs to be modified to match the analysedQuery returned from LUIS. The method might not be handling the response from LUIS causing this error. You can print the response and then make the required changes in the AnalyseResponseElements() method. This document is also not updated since 2018 but there were lot of changes on LUIS with respect to the results from the prediction endpoint, so it is likely that the document also needs an update to ensure this is working with the latest versions.
Object reference not set to an instance of an object - MR and Azure 303 tutorial
I followed the tutorial of MR and Azure 303: Natural language understanding (LUIS) https://learn.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-azure-303
In the end, I ended up getting an error on Unity that says
'"Luis Request Exception Message: Object reference not set to an instance of an object
UnityEngine.Debug:Log(Object)
<SubmitRequestToLuis>d__6:MoveNext() (at Assets/Scripts/LuisManager.cs:76)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)"
I am using a newer version of Unity, could that be the problem ?
This is the full luisManager code
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class LuisManager : MonoBehaviour
{
public static LuisManager instance;
//Substitute the value of luis Endpoint with your own End Point
string luisEndpoint = "https://luisinestest.cognitiveservices.azure.com/luis/prediction/v3.0/apps/6d954c3f-9063-4567-8bd8-196a6d1f3171/slots/production/predict?subscription-key=271f533a70fc45dba93d0b4fd8fc2842&verbose=true&show-all-intents=true&log=true&query=";
[Serializable] //this class represents the LUIS response
public class AnalysedQuery
{
public TopScoringIntentData topScoringIntent;
public EntityData[] entities;
public string query;
}
// This class contains the Intent LUIS determines
// to be the most likely
[Serializable]
public class TopScoringIntentData
{
public string intent;
public float score;
}
// This class contains data for an Entity
[Serializable]
public class EntityData
{
public string entity;
public string type;
public int startIndex;
public int endIndex;
public float score;
}
private void Awake()
{
// allows this class instance to behave like a singleton
instance = this;
}
/// <summary>
/// Call LUIS to submit a dictation result.
/// The done Action is called at the completion of the method.
/// </summary>
public IEnumerator SubmitRequestToLuis(string dictationResult, Action done)
{
string queryString = string.Concat(Uri.EscapeDataString(dictationResult));
using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString))
{
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError)
{
Debug.Log(unityWebRequest.error);
}
else
{
try
{
AnalysedQuery analysedQuery = JsonUtility.FromJson<AnalysedQuery>(unityWebRequest.downloadHandler.text);
//analyse the elements of the response
AnalyseResponseElements(analysedQuery);
}
catch (Exception exception)
{
Debug.Log("Luis Request Exception Message: " + exception.Message);
}
}
done();
yield return null;
}
}
private void AnalyseResponseElements(AnalysedQuery aQuery)
{
string topIntent = aQuery.topScoringIntent.intent;
// Create a dictionary of entities associated with their type
Dictionary<string, string> entityDic = new Dictionary<string, string>();
foreach (EntityData ed in aQuery.entities)
{
entityDic.Add(ed.type, ed.entity);
}
// Depending on the topmost recognized intent, read the entities name
switch (aQuery.topScoringIntent.intent)
{
case "ChangeObjectColor":
string targetForColor = null;
string color = null;
foreach (var pair in entityDic)
{
if (pair.Key == "target")
{
targetForColor = pair.Value;
}
else if (pair.Key == "color")
{
color = pair.Value;
}
}
Behaviours.instance.ChangeTargetColor(targetForColor, color);
break;
case "ChangeObjectSize":
string targetForSize = null;
foreach (var pair in entityDic)
{
if (pair.Key == "target")
{
targetForSize = pair.Value;
}
}
if (entityDic.ContainsKey("upsize") == true)
{
Behaviours.instance.UpSizeTarget(targetForSize);
}
else if (entityDic.ContainsKey("downsize") == true)
{
Behaviours.instance.DownSizeTarget(targetForSize);
}
break;
}
}
}
1 answer
Sort by: Most helpful
-
romungi-MSFT 42,286 Reputation points Microsoft Employee
2020-09-29T18:09:49.233+00:00