I've been trying to access the current conversation Dialogue entry id, only to be returned with a null reference exception. I have the Dialogue Manager in the scene.
I'm not sure if I need to specify the exact conversation name but when trying to Debug.Log(dialogueID), I get nothing, despite the conversation tree running.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
using System.Linq;
public class SandwichEvents : MonoBehaviour
{
/// <summary>
/// This script checks if tags of sandwich assets match the conversation entry id
/// </summary>
private int dialogueID;
public void Start()
{
// dialogueEntryID = DialogueManager.LastConversationID;
//actorID = DialogueManager.currentConversationState.subtitle.speakerInfo.id;
dialogueID = DialogueManager.currentConversationState.subtitle.dialogueEntry.id;
}
Are you sure that the conversation is already active at the time when SandwichEvents.Start() runs? You may want to check DialogueManager.isConversationActive first:
if (DialogueManager.isConversationActive)
{
dialogueID = DialogueManager.currentConversationState.subtitle.dialogueEntry.id;
}
else
{
Debug.LogWarning("No conversation is active. Can't get dialogue entry ID.");
}
If the SandwichEvents component is enabled and its GameObject is active, its Start() method will run as soon as the scene starts. This may be before the conversation starts.