Since I'm working a lot with hierarchies in character rigs I often time face , like the 12th parent of an object (such as the root of the hand that's holding the prefab weapon), and having 12 get parent actions in a row is just such a bother... so here I added an int called repetitions. 0 means it works just like before, 1 means it gets the parent of the parent of the object . The code might be a bit crude, but still, here it is:
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Gets the Parent of a Game Object.")]
public class GetParent : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
public FsmGameObject storeResult;
public int repetitions;
public override void Reset()
{
gameObject = null;
storeResult = null;
repetitions = 0;
}
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
storeResult.Value = go.transform.parent == null ? null : go.transform.parent.gameObject;
while (repetitions > 0 )
{
var go2 = storeResult.Value;
repetitions = repetitions - 1;
storeResult.Value = go2.transform.parent == null ? null : go2.transform.parent.gameObject;
}
}
else
{
storeResult.Value = null;
}
Finish();
}
}
}
Hope you can use it too