Null Reference Exception

Hello,

I am also stuck at the Null Reference Exception. I checked the other topics, but nothing works for me.

This is the error i got:

NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.Fighter.CaptureState () (at Assets/Scripts/Combat/Fighter.cs:136)
RPG.Saving.SaveableEntity.CaptureState () (at Assets/Scripts/Saving/SaveableEntity.cs:26)
RPG.Saving.SavingSystem.CaptureState (System.Collections.Generic.Dictionary`2[TKey,TValue] state) (at Assets/Scripts/Saving/SavingSystem.cs:72)
RPG.Saving.SavingSystem.Save (System.String saveFile) (at Assets/Scripts/Saving/SavingSystem.cs:29)
RPG.SceneManagement.SavingWrapper.Save () (at Assets/Scripts/SceneManagement/SavingWrapper.cs:39)
RPG.SceneManagement.Portal+d__8.MoveNext () (at Assets/Scripts/SceneManagement/Portal.cs:57)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <4746c126b0b54f3b834845974d1a9190>:0)
My player and enemies got a left and right hand transform and a default weapon ( fighter script in unity )

my scripts are:

The scripts pictures are based on the lines with the lines of the error code.
Also the private void start to change to awake doesn’t work for me.

I think i found the problem but can’t find a solution. I don’t know or this should be the only problem. the player’s Saveable Entity change from player to a another unique identifier when i go to gameplay. If i change this as player in gameplay i can go to Scene 2 with no problem and with bow,sword,unarmed or fireball, but if i go back to scene 1 he load the old savestate weapon and the the unique identifier goes back to a another unique identifier.


edit:

Okay next thing. The unique identifier does work now with player and also in different scenes.
Next problem is my player goes to a random place to start the game. How can i solve this?

But i think it should be good if we check or there a more problems if you saw my error. I hope you can help me.

It might be an idea to step through the calls in the debugger and see what’s going on, otherwise it’s guesswork.

1 Like

Just to clarify, make sure you’re using Awake(), not awake() in Fighter.cs
It does look like when changing scenes, the default weapon has not yet been loaded, which is typically a side effect of initializing in Start() instead of Awake()

1 Like

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

Privacy & Terms