i cant see what may be causing it but maybe someone else may have an answer??
void Start()
{
playerConversant = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerConversant>();
playerConversant.onConversationUpdated += UpdateUI;
nextButton.onClick.AddListener(() => playerConversant.Next());
quitButton.onClick.AddListener(() => playerConversant.Quit());
//UpdateUI();
}
so comenting out update ui removed the reference? here it the update ui method as well
void UpdateUI()
{
gameObject.SetActive(playerConversant.IsActive());
if (!playerConversant.IsActive())
{
return;
}
AIResponse.SetActive(!playerConversant.IsChoosing());
choiceRoot.gameObject.SetActive(playerConversant.IsChoosing());
if (playerConversant.IsChoosing())
{
BuildChoiceList();
}
else
{
AIText.text = playerConversant.GetText();
nextButton.gameObject.SetActive(playerConversant.HasNext());
}
}
One of the lines is calling/using something that is null. It’s hard to know what without knowing what’s on those lines 38, 94, 51, 27 of the appropriate scripts. Also helps to know what’s hooked up and/or how the data is obtained.
I suspect that the issue may be in playerConversant.IsActive()
Paste in your PlayerConversant Script and we’ll take a look.
heres the conversant
public class PlayerConversant : MonoBehaviour
{
[SerializeField] string playerName;
[SerializeField]Dialogue currentDialogue;
DialogueNode currentNode = null;
AIConversant currentConversant = null;
bool isChoosing = false;
public event Action onConversationUpdated;
public void StartDialogue(AIConversant newConversant, Dialogue newDialogue)
{
currentConversant = newConversant;
currentDialogue = newDialogue;
currentNode = currentDialogue.GetRootNode();
TriggerEnterAction();
onConversationUpdated();
}
public void Quit()
{
currentDialogue = null;
TriggerExitAction();
currentNode = null;
isChoosing = false;
currentConversant = null;
onConversationUpdated();
}
public bool IsActive()
{
return currentDialogue != null;
}
public bool IsChoosing()
{
return isChoosing;
}
public string GetText()
{
if (currentNode == null)
{
return "";
}
return currentNode.GetText();
}
public string GetCurrentConversantName()
{
if (isChoosing)
{
return playerName;
}
else
{
return currentConversant.GetName();
}
}
public IEnumerable<DialogueNode> GetChoices()
{
return currentDialogue.GetPlayerChildren(currentNode);
}
public void SelectChoice(DialogueNode chosenNode)
{
currentNode = chosenNode;
TriggerEnterAction();
isChoosing = false;
Next();
}
public void Next()
{
int numberOfPlayerResponses = currentDialogue.GetPlayerChildren(currentNode).Count();
if (numberOfPlayerResponses > 0)
{
isChoosing = true;
TriggerExitAction();
onConversationUpdated();
return;
}
DialogueNode[] children = currentDialogue.GetAIChildren(currentNode).ToArray();
int randomIndex = UnityEngine.Random.Range(0, children.Count());
TriggerExitAction();
currentNode = children[randomIndex];
TriggerEnterAction();
onConversationUpdated();
}
public bool HasNext()
{
return currentDialogue.GetAllChildren(currentNode).Count() > 0;
}
private void TriggerEnterAction()
{
if (currentNode != null)
{
TriggerAction(currentNode.GetOnEnterAction());
}
}
private void TriggerExitAction()
{
if (currentNode != null)
{
TriggerAction(currentNode.GetOnExitAction());
}
}
private void TriggerAction(string action)
{
if (action == "") return;
foreach (DialogueTrigger trigger in currentConversant.GetComponents<DialogueTrigger>())
{
trigger.Trigger(action);
}
}
}
changing the return currentDialogue != null to == null stops the dialogue from activating on the npc somehow
Once we’ve started dealing with NPCs directly, we no longer wish for this to be a Serialized Field. It’s likely been saved as a reference to a specific Dialogue in the inspector, but not tied to a particular AIConversant. Remove the [SerializeField] tag and the inspector should forget about the default reference.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.