overflows action

fukada

Member
Sorry for the basic question.
I am creating an action to be taken when the main storage overflows.
Doesn't work.

namespace Opsive.UltimateInventorySystem.ItemActions
{
using Opsive.UltimateInventorySystem.Core.InventoryCollections;
using Opsive.UltimateInventorySystem.Core.DataStructures;
using UnityEngine;

[System.Serializable]
public class OverflowToStorageAction : ItemViewSlotsContainerItemAction
{
[SerializeField] public Inventory m_StorageInventory;

public OverflowToStorageAction()
{
m_Name = "OverflowToStorage";
}

protected override bool CanInvokeInternal(ItemInfo itemInfo, ItemUser itemUser)
{
var MainStorage = GameObject.FindWithTag("Storage");
if (MainStorage == null) { Debug.Log("MainStorage null"); }
m_StorageInventory = MainStorage.GetComponent<Inventory>();

if (m_StorageInventory == null)
{ Debug.Log("Storege " + m_StorageInventory); }
return m_StorageInventory != null;
}

protected override void InvokeActionInternal(ItemInfo itemInfo, ItemUser itemUser)
{
// ストレージインベントリーに追加
m_StorageInventory.AddItem(itemInfo);
}
}
}
 
Last edited:
Happy new year!
I'm sorry for the delay I was on Holiday.

What do you mean by it doesn work? Are you getting an error?
How are you setting this item action to trigger in the itemCollection overlfow?

At a glance I see one problem. You can't reference a scene object from an ItemAction because it is usually stored in a ScriptableObject.
So:
[SerializeField] public Inventory m_StorageInventory;

Will always be null.
You should get the storage Inventory dynamically just like you do for the main inventory.
 
Back
Top