- Home /
Question by
minecrafthomie · Jun 19, 2021 at 04:32 AM ·
inventory
UNITYEXPECTION: ToString is not allowed to be called during serialization, call it from OnEnable instead.
I am making a inventory system in unity, when I add Items to this dictionary I get this error after I add the second Item to it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Item Database", menuName = "Inventory Syste/Items/Database")]
public class Itemdatatbase : ScriptableObject, ISerializationCallbackReceiver
{
public ItemObject[] Items;
public Dictionary<ItemObject, int> GetId = new Dictionary<ItemObject, int>();
public void OnAfterDeserialize()
{
GetId = new Dictionary<ItemObject, int>();
for (int i = 0; i < Items.Length; i++)
{
Debug.Log("added");
GetId.Add(Items[i], i);
}
}
public void OnBeforeSerialize()
{
}
}
Comment
following the same tutorial, getting the same errors. have you found the issue?
Your answer