Interactable destroyed check

jimi

Member
Hey there,

There is a game breaking case if a Interactable is destroyed while still serialized in the InventoryInteractor.m_Interactables array.

I've been trying to be good at making sure they are all removed but if one is missed you'll get an error thrown and will never be able to play the game without restarting.
Code:
MissingReferenceException: The object of type 'Interactable' has been destroyed but you are still trying to access it.

As a fail safe I've added an event in Interactable.OnDisable(). Just remembered to put it back after last update but thought it may be beneficial for all if it was added to UIS
Code:
        void OnDisable()
        {        
            EventHandler.ExecuteEvent<IInteractor>(gameObject, EventNames.c_Interactable_OnDeselect_IInteractor, cachedInteractor);

        }
 
In which script and at what line are you getting the error?

I think I may need to review this in more detail because there might be other use cases where this could be an issue
 
ah don't have specifics anymore. I'd imagine it was from InventoryMonitor.cs or InventoryInteractor.cs

If you remove an item while still interacting with it is when it gets thrown. ex > farm item > open ui > do harvest > remove item > close ui
 
Top