Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dialogue Problems

Discussion in 'Getting Started' started by Altanin, Aug 18, 2020.

  1. Altanin

    Altanin

    Joined:
    Jul 21, 2020
    Posts:
    15
    Hello, Im sorry in advance because I'm extremely new to coding and unity in general.
    I'm trying to enable character dialogue using 'Dialogue Editor' (see link below) in my 3d first person style game.
    I followed all the instructions however when I click on a character to start dialogue I get the error

    "NullReferenceException: Object reference not set to an instance of an object"

    I am probably missing something super obvious to most but I can't seem to find the issue in the code or in the inspector.

    This is a link to the tutorial I am following :

     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    It's unlikely this will be super obvious to anyone from what you've given. What's important is where the NullReferenceException is occurring. The full error message includes that information. In addition, if you double-click it, it should take you right to the line of code where the problem was encountered.
     
  3. Altanin

    Altanin

    Joined:
    Jul 21, 2020
    Posts:
    15
    Thank you for the response.


    NullReferenceException: Object reference not set to an instance of an object
    BirdCharacter.OnMouseOver () (at Assets/BirdCharacter.cs:16)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

    This is my full error message.
     
  4. Altanin

    Altanin

    Joined:
    Jul 21, 2020
    Posts:
    15
    I can see the error would be between the parentheses however this is exactly how the tutorial said to write this script. Here it the full script.

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

    public class BirdCharacter : MonoBehaviour
    {
    public NPCConversation myConversation;

    private void OnMouseOver()


    {
    if (Input.GetMouseButtonDown(0))
    {
    ConversationManager.Instance.StartConversation(myConversation);

    }


    }
    }
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    You're getting better at asking questions! Next please learn to use the "code" button to paste code.
    upload_2020-8-18_14-21-16.png

    That will include line numbers, so we can match up the error to the code. But I guess in this case the problem is on this line:

    Code (csharp):
    1. ConversationManager.Instance.StartConversation(myConversation);
    The error says that something on this line is null. And the only object being dereferenced on this line is ConversationManager.Instance. So, apparently ConversationManager.Instance is null.

    Now you need to go ask yourself: how is ConversationManager.Instance supposed to not be null? Were you supposed to put ConversationManager on some script in the scene? If so, are you sure you actually did that? Is the thing you put it on active, and is ConversationManager enabled?
     
  6. Altanin

    Altanin

    Joined:
    Jul 21, 2020
    Posts:
    15




    I'll make sure I include that code area next time, thankyou!

    I re-added the testconversation into the character's script and it seems to be working now! I see what you mean that it wasn't instancing the correct property. (I know it must sound super dumb when the system is screaming the error at me and I still don't get it >< )

    but anyways thank you!

    I have more questions now that this part is working but I should probably start a different thread right? :)
     
    JoeStrout likes this.
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    You're not super dumb; learning to debug takes time and is normal. You're already doing better than most.

    Hang in there! And yeah, start a new thread. :)
     
  8. Altanin

    Altanin

    Joined:
    Jul 21, 2020
    Posts:
    15
    Thank you my friend :)