Custom CraftingRecipe issue

zrrz

New member
I'm trying to get a custom `CraftingRecipe` data to show up in the ItemDatabase recipe definition

C#:
namespace Beets.Crafting
{
    using Opsive.UltimateInventorySystem.Crafting;
    using Opsive.UltimateInventorySystem.Crafting.RecipeTypes;
    using Opsive.UltimateInventorySystem.Utility;

    [OverrideCraftingIngredients(typeof(CraftingIngredientsWithCraftTime))]
    public class CraftingRecipeWithCraftTime : CraftingRecipe
    {
        [UnityEngine.SerializeField] public int craftTime = 2;

        protected override void DeserializeIngredientsInternal()
        {
            if (m_Ingredients.GetType() == typeof(CraftingIngredientsWithCraftTime)) { return; }

            var previousIngredients = m_Ingredients;
            m_Ingredients = new CraftingIngredientsWithCraftTime();
            ReflectionUtility.ObjectCopy(previousIngredients, m_Ingredients);
        }
    }
}

When I click the "Other" tab results in

Code:
InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object:Beets.Crafting.CraftingRecipeWithCraftTime.get_craftTime (int): IL_0001: ldfld     0x00000001

Making a custom CraftingIngredients like so also doesn't show anything in the Input/Other tab


C#:
namespace Beets.Crafting
{
    using Opsive.UltimateInventorySystem.Core.DataStructures;
    using Opsive.UltimateInventorySystem.Crafting;
    using UnityEngine;

    [System.Serializable]
    public class CraftingIngredientsWithCraftTime : CraftingIngredients
    {
        [Tooltip("Craft time.")]
        [SerializeField] [HideInInspector] protected float? craftTime;

        public float? CraftTime => craftTime;

        public CraftingIngredientsWithCraftTime() : base()
        {
            craftTime = new float();
        }

        public CraftingIngredientsWithCraftTime(ItemCategoryAmounts itemCategoryAmounts = null,
            ItemDefinitionAmounts itemDefinitionAmounts = null,
            ItemAmounts ItemAmounts = null,
            float? craftTime = null) : base(itemCategoryAmounts, itemDefinitionAmounts,
            ItemAmounts)
        {
            this.craftTime = craftTime ?? new float();
        }
    }
}

And I tried that with ints/floats nullable and not nullable. I'm on Unity 2020.2.0f1
 
Last edited:
You are right there is an error for floats and ints (the last time I tested I did it with a string which doesn't have that error)... They work fine though so I think you can ignore that error while we try to get it fixed.

For floats the error is:
C#:
InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object:Examples._CustomCrafting.CustomCraftingRecipe.get_m_CraftTime (single): IL_0001: ldfld     0x00000001


System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) (at <437ba245d8404784b9fbab9b439ac908>:0)
Opsive.Shared.Editor.UIElements.BindingUpdater+Binding.CreateGetter (System.Reflection.FieldInfo field, System.Object target) (at Assets/Opsive/Shared/Editor/UIElements/BindingUpdater.cs:90)
Opsive.Shared.Editor.UIElements.BindingUpdater+Binding..ctor (System.Reflection.FieldInfo field, System.Int32 arrayIndex, System.Object target, System.Action`1[T] onBindingUpdateEvent) (at Assets/Opsive/Shared/Editor/UIElements/BindingUpdater.cs:59)
Opsive.Shared.Editor.UIElements.BindingUpdater.AddBinding (System.Reflection.FieldInfo field, System.Int32 arrayIndex, System.Object target, System.Action`1[T] onBindingUpdateEvent) (at Assets/Opsive/Shared/Editor/UIElements/BindingUpdater.cs:183)
Opsive.Shared.Editor.UIElements.Controls.Types.FloatControl+<>c__DisplayClass2_1.<GetControl>b__3 (UnityEngine.UIElements.AttachToPanelEvent c) (at Assets/Opsive/Shared/Editor/UIElements/Controls/Types/FloatControl.cs:45)
UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt) (at <a6a3aac9b47844afbb8dcc407683ae01>:0)

For ints the error is:
C#:
InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object:Examples._CustomCrafting.CustomCraftingRecipe.get_m_CraftTime (int): IL_0001: ldfld     0x00000001


System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) (at <437ba245d8404784b9fbab9b439ac908>:0)
Opsive.Shared.Editor.UIElements.BindingUpdater+Binding.CreateGetter (System.Reflection.FieldInfo field, System.Object target) (at Assets/Opsive/Shared/Editor/UIElements/BindingUpdater.cs:90)
Opsive.Shared.Editor.UIElements.BindingUpdater+Binding..ctor (System.Reflection.FieldInfo field, System.Int32 arrayIndex, System.Object target, System.Action`1[T] onBindingUpdateEvent) (at Assets/Opsive/Shared/Editor/UIElements/BindingUpdater.cs:59)
Opsive.Shared.Editor.UIElements.BindingUpdater.AddBinding (System.Reflection.FieldInfo field, System.Int32 arrayIndex, System.Object target, System.Action`1[T] onBindingUpdateEvent) (at Assets/Opsive/Shared/Editor/UIElements/BindingUpdater.cs:183)
Opsive.Shared.Editor.UIElements.Controls.Types.IntControl+<>c__DisplayClass2_1.<GetControl>b__3 (UnityEngine.UIElements.AttachToPanelEvent c) (at Assets/Opsive/Shared/Editor/UIElements/Controls/Types/IntControl.cs:47)
UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt) (at <a6a3aac9b47844afbb8dcc407683ae01>:0)

The same line of code is triggering the error. @Justin could you have a look at that?

zrrz as you can see below the value does show and can be edited (it serializes correctly). The error should be specific to the editor, so you shouldn't have any issues at runtime.

1611219733244.png
The crafting recipe code:
C#:
namespace Examples._CustomCrafting
{
    using Opsive.UltimateInventorySystem.Crafting;
    using UnityEngine;
    
    public class CustomCraftingRecipe : CraftingRecipe
    {
        [SerializeField] protected int m_CraftTime;
    }
}
 
1611223800447.png
Yea I'm just getting a blank area when I try that code.


C#:
namespace Beets.Crafting
{
    using Opsive.UltimateInventorySystem.Crafting;

    public class CraftingRecipeWithCraftTime : CraftingRecipe
    {
        [UnityEngine.SerializeField] protected int m_craftTime = 2;
    }
}
Not sure what else I can do to try to fix it or to try to help track down the issue.

I can get it to work for now using a string to hold the int, but that is super janky so it's only a temporary solution.
 
It's good to know you found a work around for now.

We believe that we were able to fix that bug. The fix will be part of the update v1.1.4 coming up next week
 
I'm running into the same issue as zrrz has above. Running v1.1.4 of UIS as well.

Code:
using UnityEngine;

namespace Opsive.UltimateInventorySystem.Crafting.RecipeTypes
{
    public class CraftingRecipeWithTime : CraftingRecipe
    {
        [SerializeField] protected float m_CraftTime;

        public float CraftTime => m_CraftTime;
    }
}

Getting the same error when clicking on the "other" tab in the Crafting Recipes editor window:
Code:
InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object:Opsive.UltimateInventorySystem.Crafting.RecipeTypes.CraftingRecipeWithTime.get_m_CraftTime (single): IL_0001: ldfld     0x00000001

Any ideas on what I could try to fix it? (or more information I can provide?)

I'm running Unity version 2020.2.2f1.
 
@cptscrimshaw Are you sure you are using v1.1.4? Please double check in the bottom left of the Welcome Menu in the Editor Manager. Sometimes the Unity Package Manager says the package is up to date but it isn't. Refer to the second paragraph of the release notes:
 
Top