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
- This topic has 21 replies, 3 voices, and was last updated 8 months ago by Pete.
-
AuthorPosts
-
April 18, 2024 at 7:09 pm #13970::
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)
April 18, 2024 at 7:26 pm #13973::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.
- On your Camera Prefab, remove the second CameraManager.cs you have on it
- Replace the CameraManager.cs script, you can use the same setup as before you deleted it
- Replace the Camera Prefab in the scene
- Remake the Camera Prefab without using the Prefab.
You can also try this while using the print code from the previous step:
- Move your
UpdateCameraYDampForPlayerFall();
under yourMove()
inUpdate()
- 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?April 18, 2024 at 10:27 pm #13983::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.
April 18, 2024 at 11:22 pm #13984::Again, as I pointed out, the reason for this is because the call for
UpdateCameraYDampForPlayerFall();
method is failing in theUpdate()
. Thus, all methods called beforeUpdateCameraYDampForPlayerFall();
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
April 19, 2024 at 1:06 am #13986::I called
UpdateCameraYDampForPlayerFall();
last ofUpdate()
, 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
- On your Camera Prefab, remove the second CameraManager.cs you have on it
- Replace the CameraManager.cs script, you can use the same setup as before you deleted it
- Replace the Camera Prefab in the scene
- Remake the Camera Prefab without using the Prefab.
April 19, 2024 at 1:37 am #13987::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
April 19, 2024 at 2:10 am #13989 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: