BindingUpdater error when using custom recipes

desukarhu

Member
Hey,

Following up from discord. So I'm getting this error when I open the "Other" tab when editing a crafting recipe in the editor:
Code:
[Exception] NullReferenceException: Object reference not set to an instance of an object
BindingUpdater+Binding.Update() at <d64ce463719e4c3ea88be690b831f279>:0

BindingUpdater.UpdateBindings() at <d64ce463719e4c3ea88be690b831f279>:0

EditorApplication.Internal_CallUpdateFunctions() at <1c8c981f35e342fb96463e6793772537>:0
It doesn't give me a better trace of it so I don't know where it happens. It just keeps spamming in the console. Even if I close the UIS main window or disable all the UIS stuff in the hierarchy. The only thing that stops it from happening is changing scenes or restarting Unity.

This is my custom crafting recipe:
Code:
namespace Opsive.UltimateInventorySystem.Crafting.RecipeTypes {
  using Opsive.UltimateInventorySystem.Core;

  using UnityEngine;
  public class LeveledCraftingRecipe : CraftingRecipe {
    public int LevelRequirement;
    public ItemDefinition ItemRequirement;
  }
}

I noticed that if those two variables are set to protected with [SerializeField] the error doesn't happen. But I need to be able to access them from my code.

I'm using Unity 2021.1 and UIS 1.1.8.
 
Thank you for the information. knowing that the error only happens if the fields are public and not protected might help diagnose this issue.

In the meantime if it works with serialized protected simply use a seperate public property, we do this all the time in the source code:
(Not tested pseudo code)
Code:
[SerializeField] protected int m_LevelRequirement;

public int LevelRequirement {get => m_LevelRequirement; set => m_LevelRequirement = value;}
 
Thank you for the information. knowing that the error only happens if the fields are public and not protected might help diagnose this issue.

In the meantime if it works with serialized protected simply use a seperate public property, we do this all the time in the source code:
(Not tested pseudo code)
Code:
[SerializeField] protected int m_LevelRequirement;

public int LevelRequirement {get => m_LevelRequirement; set => m_LevelRequirement = value;}
Thanks, I tried that but didn't help, so I think the protection level is irrelevant after all.

BUT, testing it I accidentally made both variables int and I didn't get the error. So knowing that, it seems like it's the ItemDefinition field that causes the error.

I also tested ItemCategory and ItemRecipe just to see, and they also cause the error. Seems like basic stuff like int, float and strings do work.

So for now I can use just a string field for the ItemRequirement and then use that to check if the player has an item with that name. It feels bad to use strings but it'll work for now.
 
I was able to dig deeper into this issue. It seems it happens for all Unity Objects.
I was able to prevent the error from happening but we are still looking into why it happens in the first place because that's still not clear.

While I was at it I also added some custom controls for ItemDefinition and Item Definition Amounts and made sure it worked in this "Other" tab.
1632913914024.png

Now I'll add some controls for categories, recipes, currency, etc... it's nicer having a search list with the colors and icons.
All this will be availble in the next update, I hope you're looking forward to it.
 
I was able to dig deeper into this issue. It seems it happens for all Unity Objects.
I was able to prevent the error from happening but we are still looking into why it happens in the first place because that's still not clear.

While I was at it I also added some custom controls for ItemDefinition and Item Definition Amounts and made sure it worked in this "Other" tab.
View attachment 7329

Now I'll add some controls for categories, recipes, currency, etc... it's nicer having a search list with the colors and icons.
All this will be availble in the next update, I hope you're looking forward to it.
Yeah it seems like a weird error to happen. I'm glad you found a way to surpress the error at least since it doesn't seem to break anything.

That update looks great, can't wait!
 
Top