Forum begins after the advertisement:


[Part 6] Repititive NullReferenceException error

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 6] Repititive NullReferenceException error

Viewing 2 posts - 21 through 22 (of 22 total)
  • Author
    Posts
  • #13987
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    After a grueling effort. I’ve sent your code through ChatGPT, and I’m happy to say that I’ve found the issue.

    The problem was in your CameraManager.cs Awake() method.

    private void Awake()
        {
            if (Instance = == null)
            {
                Instance = this;
            }
        }

    It’s almost impossible to recognize this as there is no errors with it and such…

    The comparison operator = is used for assignment, not for comparison. Therefore, the condition if(Instance = null) will always assign null to Instance, and the code inside the if block will always execute.

    This was such a small piece of code that it had me and you stumped. Tell me if it works

    #13989
    Pete
    Level 3
    Participant
    Helpful?
    Up
    0
    ::

    Finally…it worked. My small mistake took so much time on it.

    Thanks for your help.

    I really appreciate it!!!

Viewing 2 posts - 21 through 22 (of 22 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: