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 7 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.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 yourUpdateCameraYDampForPlayerFall();
under yourMove()
inUpdate()
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?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.void Update() { if (pState.cutscene) return; GetInputs(); UpdateJumpVariables(); RestoreTimeScale(); if (pState.dashing) return; Flip(); Move(); Jump(); StartDash(); Attack(); FlashWhileInvincible(); Heal(); CastSpell(); UpdateCameraYDampForPlayerFall(); }
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.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 worksApril 19, 2024 at 2:10 am #13989 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: