Hi, I'm in the process of learning to create my own custom actions. I did some progress but now I found a problem I don't know how to solve.
I'm doing a custom action to add an item using Inventory Engine. I managed to make it work to a basic level, but when I try to pass the "item" variable to playmaker somehow the "prefab" item gets lost during runtime.
It must be a way because I manage to pass the variable using the Call Method action.
This is my code:
using UnityEngine;
using MoreMountains.InventoryEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Inventory Engine")]
[Tooltip("Add an item to the Inventory Engine plugin. The item must be a prefab created using the InventoryEngine menu.")]
public class AddItem : FsmStateAction
{
// Define the gameObject owner of the Inventory script.
[RequiredField]
[Tooltip("The GameObject where the Inventory script is.")]
public FsmOwnerDefault scriptOwner;
[RequiredField]
[Tooltip("Attach the prefab object to add as an item.")]
public FsmObject Item;
private InventoryItem prefab;
[RequiredField]
[Tooltip("How many of the previous item must be added to the Inventory.")]
public FsmInt numberOfItemsAdd;
Inventory inventoryScript;
// Code that runs on entering the state.
public override void OnEnter()
{
Item = prefab;
inventoryScript = scriptOwner.GameObject.Value.GetComponent<Inventory>();
inventoryScript.AddItem(prefab, numberOfItemsAdd.Value);
Finish();
}
}
}