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 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #13970
    Pete
    Level 3
    Participant
    Helpful?
    Up
    0
    ::

    In console, Null is returned.

    here’s the console message.

    Null UnityEngine.MonoBehaviour:print (object) PlayerController:UpdateCameraYDampForPlayerFall () (at Assets/Scripts/PlayerController.cs:252) PlayerController:Update () (at Assets/Scripts/PlayerController.cs:184)

    #13973
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    At this point, it seems almost clear that your scripts are fully correct and the issue is with the setup somehow. Return your code back to before the previous instruction. Okay, this is not solid and might not work, however do test the game after every step.

    1. On your Camera Prefab, remove the second CameraManager.cs you have on it
    2. Replace the CameraManager.cs script, you can use the same setup as before you deleted it
    3. Replace the Camera Prefab in the scene
    4. Remake the Camera Prefab without using the Prefab.

    You can also try this while using the print code from the previous step:

    1. Move your UpdateCameraYDampForPlayerFall(); under your Move() in Update()
    2. Check for errors, or if the camera has been properly set.

    Also, There seems to be another error at PlayerController.cs:184? Which code in the Update() is 184?

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

    As I tried your “1) Move your UpdateCameraYDampForPlayerFall(); under your Move() in Update()” the character can move horizontally but other movement is not working ex) attacking, jumping, skills

    and after I attached SceneFader to UIManager script, I think scene transitioning is working.

    But still there are repetitive error message on console.

    I’ll show the video of result.

    #13984
    Joseph Tang
    Level 13
    Moderator
    Helpful?
    Up
    0
    ::

    Again, as I pointed out, the reason for this is because the call for UpdateCameraYDampForPlayerFall(); method is failing in the Update(). Thus, all methods called before UpdateCameraYDampForPlayerFall(); will work while the ones after won’t.

    How goes the other steps other than (1)? Test all of them to see for any result and how it went

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

    I called UpdateCameraYDampForPlayerFall();last of Update(), now all of character’s movement is working.

    <code>void Update()
    {
        if (pState.cutscene) return;
    
        GetInputs();
        UpdateJumpVariables();
    
        RestoreTimeScale();
    
        if (pState.dashing) return;
        Flip();
        Move();
        Jump();
        StartDash();
        Attack();
        FlashWhileInvincible();
        Heal();
        CastSpell();
    
        UpdateCameraYDampForPlayerFall();
    }</code>

    But I tested all of these step, but nothing has changed with Ydamping

    1. On your Camera Prefab, remove the second CameraManager.cs you have on it
    2. Replace the CameraManager.cs script, you can use the same setup as before you deleted it
    3. Replace the Camera Prefab in the scene
    4. Remake the Camera Prefab without using the Prefab.
    #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 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: