Hopefully this Action will return a String variable of the Path of a GameObject.
using UnityEngine;
#pragma warning disable 168
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Returns the String of the Path of the selected GameObject.")]
public class GetGameObjectPath : FsmStateAction
{
[RequiredField]
[Tooltip("The GameObject from which you return a String of its Path.")]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Store the final String of the GO's Path in a variable.")]
public FsmString storeResult;
private string result;
private Transform tf;
private string name;
public override void Reset()
{
gameObject = null;
storeResult = null;
}
public override void OnEnter()
{
Find();
Finish();
}
void Find()
{
var go1 = Fsm.GetOwnerDefaultTarget(gameObject);
tf = go1.transform;
result = tf.name;
while (tf.parent != null)
{
tf = tf.parent;
result = tf.name + "/" + result;
}
storeResult.Value = result;
}
}
}