Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: kiriri on May 27, 2012, 08:59:09 AM

Title: get n-th parent
Post by: kiriri on May 27, 2012, 08:59:09 AM
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:

Code: [Select]
// (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  ;D
Title: Re: get n-th parent
Post by: 600 on August 05, 2015, 08:21:18 AM
Hi... 3 years later... thanks! This is very usefull!

Can someone look at this and make a version where the action finds the source parent (parented to the world) without hard coded repetitions?
Or is there an action for such a feature to get the Main game object holding all childs?
Title: Re: get n-th parent
Post by: sebaslive on August 06, 2015, 10:26:34 AM
In case anyone else needs this, there is an action called "get root" that will get the root parent object from any child.
Title: Re: get n-th parent
Post by: 600 on August 06, 2015, 10:33:19 AM
^  ;D
Title: Re: get n-th parent
Post by: jeanfabre on August 17, 2015, 02:42:06 PM
Hi,

 Do you have the link to the "Get root" action?

 Bye,

 Jean
Title: Re: get n-th parent
Post by: 600 on August 17, 2015, 02:48:13 PM
It comes by default in Playmaker
Title: Re: get n-th parent
Post by: jeanfabre on August 17, 2015, 04:56:48 PM
ah!

learning everyday, thanks :)

Bye,

 Jean