Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Alatriste on January 21, 2019, 09:29:11 AM
-
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();
}
}
}
-
Hi,
is it not because you are referencing the prefab asset and not the prefab instance in the scene?
BYe,
Jean
-
Most probably... Although I don't have a clue about how to change it.
I was looking for some script examples, but it seems to be different in this case, as the variable "prefab" belongs to the InventoryItem.
(I'm doing a C# course in Udemy but I'm already trying things... :P)
-
Hi,
You should debug using a FsmGameObject variable where you put that gameobject, ad then you log it in the Unity log using UnityEngine.Debug.Log("sdasd",thegameobjectreference), this way whe you click on the log it will ping it in the scene or in the assets and you'll know.
else you can also use https://docs.unity3d.com/ScriptReference/EditorUtility.IsPersistent.html
Bye,
Jean