playMaker

Author Topic: Get Game Object Path  (Read 381 times)

Duffer

  • Playmaker Newbie
  • *
  • Posts: 26
    • View Profile
Get Game Object Path
« on: March 18, 2017, 02: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;
        }
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12671
  • Official Playmaker Support
    • View Profile
Re: Get Game Object Path
« Reply #1 on: April 11, 2017, 12: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




 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