Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started 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:
// (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
-
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?
-
In case anyone else needs this, there is an action called "get root" that will get the root parent object from any child.
-
^ ;D
-
Hi,
Do you have the link to the "Get root" action?
Bye,
Jean
-
It comes by default in Playmaker
-
ah!
learning everyday, thanks :)
Bye,
Jean