[Bug] Null Reference Exception when interacting with the blacksmith in demo scene

Cheo

Active member
Hello, I finally decided to delve into UIS, but only 2 minutes into the demo scene I stumbled upon a bug - when interacting with the blacksmith I get a null reference exception, here's the stack and source :

Code:
[Exception] NullReferenceException: Object reference not set to an instance of an object
CraftingMenuBase+MultiCraftingRecipeFilterSorter.Filter() at /Opsive/UltimateInventorySystem/Scripts/UI/Menus/Crafting/CraftingMenuBase.cs:300
 298:  for (int i = 0; i < m_GridFilters.Count; i++) {
 299:      if(m_GridFilters[i] == this){ continue; }
--> 300:      list = m_GridFilters[i].Filter(list, ref outputPooledArray);
 301:  }

Opsive.UltimateInventorySystem.UI.Grid.GridGeneric`1[T].SetElements() at /Opsive/UltimateInventorySystem/Scripts/UI/Grid/GridGeneric.cs:353
 351:  if (ignoreSorterFilter == false && m_FilterSorter != null) {
 352:      var pooledArray = GenericObjectPool.Get<T[]>();
--> 353:      newElements = m_FilterSorter.Filter(newElements, ref pooledArray);
 354:      GenericObjectPool.Return(pooledArray);
 355:  }

CraftingMenuBase.DrawRecipes() at /Opsive/UltimateInventorySystem/Scripts/UI/Menus/Crafting/CraftingMenuBase.cs:124
 122:  public virtual void DrawRecipes()
 123:  {
--> 124:      m_CraftingRecipeGrid.SetElements(m_Crafter.GetRecipes());
 125:      m_CraftingRecipeGrid.Draw();
 126:  }

CraftingMenuBase.SetCrafter() at /Opsive/UltimateInventorySystem/Scripts/UI/Menus/Crafting/CraftingMenuBase.cs:116
 114:      m_Crafter = crafter;
 115:      m_Crafter.Initialize(false);
--> 116:      DrawRecipes();
 117:  }

CraftingMenuOpener.Open() at /Opsive/UltimateInventorySystem/Scripts/UI/Menus/CraftingMenuOpener.cs:32
  30:  {
  31:      m_Menu.BindInventory(inventory);
-->  32:      m_Menu.SetCrafter(m_Crafter);
  33:      m_Menu.DisplayPanel.SmartOpen();
  34:  }

MenuInteractableBehavior.OnInteractInternal() at /Opsive/UltimateInventorySystem/Scripts/UI/Panels/MenuInteractableBehavior.cs:37
  35:              m_MenuOpener.ChangePanelManagerIndex(interactorWithInventory.Inventory.gameObject.GetCachedComponent<InventoryIdentifier>().ID);
  36:          }
-->  37:          m_MenuOpener.Open(interactorWithInventory.Inventory);
  38:      }
  39:  }

InteractableBehavior.OnInteract() at /Opsive/UltimateInventorySystem/Scripts/Interactions/InteractableBehavior.cs:100
  98:  public virtual void OnInteract(IInteractor interactor)
  99:  {
--> 100:      OnInteractInternal(interactor);
 102:      if (!m_DeactivateOnInteract) { return; }

Opsive.Shared.Events.InvokableAction`1[T1].Invoke() at <52329c5bb9d24a17aa3c9cbeab267298>:0

EventHandler.ExecuteEvent[T1]() at <52329c5bb9d24a17aa3c9cbeab267298>:0

Interactable.Interact() at /Opsive/UltimateInventorySystem/Scripts/Interactions/Interactable.cs:180
 179:      m_OnInteract.Invoke();
--> 180:      EventHandler.ExecuteEvent<IInteractor>(gameObject, EventNames.c_Interactable_OnInteract_IInteractor, interactor);
 181:      return true;
 182:  }

InventoryInteractor.InteractWith() at /Opsive/UltimateInventorySystem/Scripts/Interactions/InventoryInteractor.cs:163
 161:  protected virtual void InteractWith(IInteractable interactable)
 162:  {
--> 163:      interactable.Interact(this);
 164:  }

InventoryInteractor.Interact() at /Opsive/UltimateInventorySystem/Scripts/Interactions/InventoryInteractor.cs:112
 110:  {
 111:      if (m_Interactables.Count > 0) {
--> 112:          InteractWith(m_Interactables[0]);
 113:      }
 114:  }

InventoryInteractor.Update() at /Opsive/UltimateInventorySystem/Scripts/Interactions/InventoryInteractor.cs:102
 101:      if (m_Input.CheckInput(m_PlayerInput)) {
--> 102:          Interact();
 103:      }
 104:  }

I just downloaded UIS so it's the latest version, 1.12.18. I'm using Unity 2022.3.8f1.

As I've already said for issues in other demo scenes, this is really a shame, when I start a demo scene I'm expecting to have a good example and to be able to play around with the asset, not to have to write a bug report just a few minutes after installing the asset ! Hope you can fix this, I'll see if I can figure this out already.
 
I'm very sorry about that.
I usually test out the demo scene and the editors each time we make an update. I don't know how that slipped through.

Please add a null check on line 299 of the CraftingMenuBase.cs script:
if(m_GridFilters == null || m_GridFilters == this){ continue; }

That should solve this issue
 
Sorry, but there are 2 issues about that line - first, "m_GridFilters == this" creates an error in vs that says "Operator '==' cannot be applied to operands of type 'List<IFilterSorter<CraftingRecipe>>' and 'CraftingMenuBase.MultiCraftingRecipeFilterSorter'". It can be fixed by adding an "i" between square brackets (how do you write that in a post ? it gets erased) right next to m_GridFilters like in the existing check, which is I suppose what you had in mind ?

But even with this fix the exact same error is still thrown ! Doesn't it occur on your end ? In any case here is a video showing what it's like on my end if that helps :

 
Ah, okay, an i between square brackets was necessary for both ! Thanks, it works now !
 
This has been driving me crazy for days, for others who are more visual like me.. this is the console error:

This does fix it. Thanks!

Line 299 for me:

if(m_GridFilters == null || m_GridFilters == this){ continue; }


Double click that error and open the visual editor to fix.

Unity_2hvHE6BPVG.png
 
Top