Null references im failing to solve

Im getting a null reference error that leads to the UpdateUI methods line we added in this script. i know its something small im missing but i cant find it for the life of me…

//from DialogueUI

void UpdateUI()
{
gameObject.SetActive(_playerConversant.IsActive());
if(!_playerConversant.IsActive())
{
return;
}

        _conversantName.text = _playerConversant.GetCurrentConversantName();
        AIResponse.SetActive(!_playerConversant.IsChoosing());
        _choiceRoot.gameObject.SetActive(_playerConversant.IsChoosing());
       

        if(_playerConversant.IsChoosing())
        {
            BuildChoiceList();
        }
        else
        {
            _AIText.text = _playerConversant.GetText();
            _nextButton.gameObject.SetActive(_playerConversant.HasNext());
        }


        
    }

//from PlayerConversant

public string GetCurrentConversantName()
{
if(isChoosing)
{
return _playerName;
}
else
{
return _currentConversant.GetName();
}
}

Inspector on enemy with dialogue trigger

Inspector on player (Im 90% sure i don’t need dialogue in the players CurrentDialogue field anymore… but i tried with and without

image

this is the error in full

i dont think it matters but as my script is not identical to the projects… line 29 of the AI conversant( referenced in error log) is he StartDialogue line of HandleRaycast

public bool HandleRaycast(PlayerController callingController)
{
if(_AIQuest == null)
{
return false;
}
if (Input.GetMouseButtonDown(0))
{
PlayerConversant playerConversant = callingController.GetComponent();
playerConversant.StartDialogue(this, _AIQuest);
}
return true;
}

There error happens on line 56 of DialogueUI.cs. You didn’t paste all the code of that script so it’s difficult to know which line that is

Sorry i thought i had pointed it out . when i said

… but i guess people arent trying to watch the whole video or check read the repo if it can be avoided. so that is basically a useless way of telling someone trying to help where the line is.

this is the line

_conversantName.text = _playerConversant.GetCurrentConversantName();

it passes through to Get method on the next section down in original comment.

I didn’t check the original code because you also said this

Anyway, only two things can be null, here: _conversantName and _playerConversant

You can check if either of those are null before this line 56. Once you know which one it is, you can figure out why it is null. Just put a Debug.Log(_conversantName); and Debug.Log(_playerConversant); and one of those will print ‘null’ in the console

1 Like

Thanks man! My head must not be in the game today. I realize what happened. I did the video as a challenge. Originally i had the variable named _name, I changed it to be _conversantName to closer match the code given by instructor. i usually do this after a challenge then re-map references that brake. this time i forgot i had conversant name. silly mistake.

also thanks for pointing out a debug method. i should have thought to do that.

sorry if my reply came across weird. It read a bit more passive-aggressive than i meant for it to when i re-read. just a bit tired from a long week traveling for work.

1 Like

It’s all good.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms