Hey All,
I’ve been working through the RPG Core classes and got pretty much to the end, however, the save system is causing an issue now with loading weapons. I’ve set up several Debu.Logs in RestoreState:
public void RestoreState(object state)
{
Debug.Log("Loading state: " + state);
string weaponName = (string)state;
Debug.Log("Loading weaponName: " + weaponName);
Weapon weapon = UnityEngine.Resources.Load<Weapon>(weaponName);
Debug.Log("Loading Weapon: " + weapon);
EquipWeapon(weapon);
And the first two Debugs return Unarmed since that is the equipped weapon, however, the 3rd Debug returns nothing and the error message is:
NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.PlayerFighter.AttachWeapon (RPG.Combat.Weapon weapon) (at Assets/Scripts/Combat/PlayerFighter.cs:41)
RPG.Combat.PlayerFighter.EquipWeapon (RPG.Combat.Weapon weapon) (at Assets/Scripts/Combat/PlayerFighter.cs:36)
RPG.Combat.PlayerFighter.RestoreState (System.Object state) (at Assets/Scripts/Combat/PlayerFighter.cs:94)
RPG.Saving.SaveableEntity.RestoreState (System.Object state) (at Assets/Scripts/Saving/SaveableEntity.cs:39)
RPG.Saving.SavingSystem.RestoreState (System.Collections.Generic.Dictionary2[TKey,TValue] state) (at Assets/Scripts/Saving/SavingSystem.cs:85) RPG.Saving.SavingSystem.Load (System.String saveFile) (at Assets/Scripts/Saving/SavingSystem.cs:35) RPG.SceneManagement.SavingWrapper.Load () (at Assets/Scripts/Core/SavingWrapper.cs:27) UnityEngine.Events.InvokableCall.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:178) UnityEngine.Events.UnityEvent.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_0.cs:58) UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction
1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)
I’m not sure what the issue is. Does anyone have any thoughts on what can be done to fix it or diagnose the issue?
Thanks