Null reference when going through portal

I am getting a null reference when trying to go through the portal. The error points to the capture state in the fighter script for what the current weapon is.

I narrowed it down to at what stage of the portal transition it is happening. As it is set up, the portal will fade out, save, load the new scene, then load the save data, get the other portal, then attempt to save once again. It is at this point that it craps out.

At some point, the reference to the current weapon is getting lost and I am not sure where to track this down at. I’ve done my best to compare everything I have with the lesson scripts thus far.

Not sure what info you need, so let me know and ill provide whatever is necessary.

This is a common one. The trouble lies in part of the timing of the saving system. First, the game loads the new scene (including our new player). Awake is called immediately. Then the saving system Loads everything and saves it again, this happens BEFORE Start. This causes a null reference if the weapon is being initialized in Start(). Try moving it to Awake().
This isn’t the only race condition. There is another one with Fader that can prevent the new scene from loading. Moving the canvasGroup=GetComponent(); from Start() to Awake() will fix this one too.

My god, that was it. Thank you so much, I was about to start pulling hair out over this.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.