Certain code in method not being called

HI everyone,

I am having an issue where only the Debug.Log is being run in a funcitonI have defined. I have created a dialogue system and I want to reset the players camera and speaking variables when finished with the dialogue, however, I can see only the Debug.Log is being run, but neither the camera or speaking variable are set.

I have this code in my dialogue script for when conversation is over:

public void EndDialogue()
{
    dialogueBox.SetActive(false);
    addSentencesToQueue = false;
    dialogueEnded = true;

    Debug.Log("EndDialogue");
    // TODO - see if there's a better way to do this, ideally, manager shouldn't need to reference the player
    GameObject.FindGameObjectWithTag("Player").GetComponent<InitiateDialogue>().ResetPlayer();
}

And I can see this gets called

image

As you can see, I call the ResetPlayer function here which is simply the following function maintained on a script on the player:

public void ResetPlayer()
{
    Debug.Log("Reset");
    playerMovement.isSpeaking = false;
    cinemachineCamera.Follow = CameraLookAtPoint;
}

I can also see that the “Reset” gets called in the editor

image

But the isSpeaking and cinemachine Follow variables are not changed. I’m not updating them anywhere else and they can be changed at run time, so I’m just wondering how come the Debug.Log is printed but my other variables don’t seem to be affected, from what I can see, everything should be working fine, but I could be overlooking something small.

I’m using Unity 6 if that helps.

Thanks

Just to test, I created a new variable called test in the InitiateDialogue script and changed the ResetPlayer code so that it changed this variable to “filled” once called. I can confirm that this works as expected and the string variable is filled once the dialogue finishes.

The code simply doesn’t work for the isSpeaking/cinemachine properties and I’m not exactly sure why

Turns out this was a script logic execution issue (mainly me overlooking the problem). I had the following code running each time I pressed the interact button

if (interact.action.triggered == true)
{
    Collider[] colliderArray = Physics.OverlapSphere(transform.position, interactableRange);
    foreach (Collider collider in colliderArray)
    {
        // Only want the physics collider to detect the trigger maintained on the NPC
        if (collider.isTrigger)
        {
            // Check if the the object has the dialogue trigger script
            if (collider.TryGetComponent(out DialogueTrigger dialogueTrigger))
            {

                dialogueTrigger.Interact();
                if (!DialogueManager.Instance.DialogueEnded()) // I added this to prevent the issue
                {
                    playerMovement.isSpeaking = true;
                    middlePoint.transform.position = (transform.position + dialogueTrigger.transform.position) / 2;
                    cinemachineCamera.Follow = middlePoint;

                }
            }

        }
    }
}

What was happening is this code was running again when the dialogue was finished. So I was pressing the interact to close the dialogue box (which would reset the variables from the ResetPlayer function that is called from the EndDialogue script which is called from DialogueEnded, but then immediately after this, the isSpeaking and cinemachine variables were being set again, despite dialogue being finished.

I put an if statement to prevent the variables from being updated if the dialogue was finished.