InventoryBridgeSaver MissingReferenceException with scene change.

jimi

Member
Hi,

I'm having an issue when attempting to load a scene if it was already loaded. Here is the error stack:
Code:
MissingReferenceException: The object of type 'InventoryBridgeSaver' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.InventoryBridgeSaver.OnWillStartLoading (System.Int32 saveIndex) (at D:/works/Subdivided_URP2/Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/InventoryBridgeSaver.cs:132)
Opsive.Shared.Events.InvokableAction`1[T1].Invoke (T1 arg1) (at <27da9e1afec54f2fb2a11d46a234f9df>:0)
Opsive.Shared.Events.EventHandler.ExecuteEvent[T1] (System.String eventName, T1 arg1) (at <27da9e1afec54f2fb2a11d46a234f9df>:0)
Opsive.UltimateInventorySystem.SaveSystem.SaveSystemManager.LoadInternal (System.Int32 saveIndex) (at D:/works/Subdivided_URP2/Assets/Opsive/UltimateInventorySystem/Scripts/SaveSystem/SaveSystemManager.cs:440)
Opsive.UltimateInventorySystem.SaveSystem.SaveSystemManager.Load (System.Int32 saveIndex) (at D:/works/Subdivided_URP2/Assets/Opsive/UltimateInventorySystem/Scripts/SaveSystem/SaveSystemManager.cs:232)
GoneUpstateManager+<_LoadGame>d__66.MoveNext () (at Assets/Scripts/GoneUpstateManager.cs:113)
The load is being called like this:
Code:
        SaveSystemManager.Load(slot);

The saved game file loads correctly when you start the game and load the scene from the main menu. But if you return to the main menu and load the scene again this error occurs.
 
Looks like I forgot to unregister from the event.

Add this to the Inventory Bridge Saver script:
Code:
/// <summary>
/// Unregister events on destroy.
/// </summary>
protected override void OnDestroy()
{
    base.OnDestroy();
    EventHandler.UnregisterEvent<int>(EventNames.c_WillStartLoadingSave_Index, OnWillStartLoading);
}

Let me know if that fixes your issue or if something else breaks.
 
Top