Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Duffer on March 18, 2017, 05:38:17 AM

Title: Get Game Object Path
Post by: Duffer on March 18, 2017, 05:38:17 AM
Hopefully this Action will return a String variable of the Path of a GameObject.

Code: [Select]
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;
        }
}
}
Title: Re: Get Game Object Path
Post by: jeanfabre on April 11, 2017, 03:04:00 AM
Hi,

 Cool, I made a version based on your action and it's on the Ecosystem now:

https://twitter.com/JeanAtPlayMaker/status/851692025930014720

(https://pbs.twimg.com/media/C9HRGT-WsAA9cYX.jpg)
(https://pbs.twimg.com/media/C9HQ9KnXgAASVxQ.jpg)

 it allows you to choose to include gameobject source or not, and also save each parent individually as names or go as you wish.

 Bye,

 Jean