playMaker

Author Topic: get n-th parent  (Read 4095 times)

kiriri

  • Hero Member
  • *****
  • Posts: 506
get n-th parent
« 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
« Last Edit: May 27, 2012, 09:10:28 AM by kiriri »
Best,
Sven

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • Flashing Lights
Re: get n-th parent
« Reply #1 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?

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: get n-th parent
« Reply #2 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.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • Flashing Lights
Re: get n-th parent
« Reply #3 on: August 06, 2015, 10:33:19 AM »
;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: get n-th parent
« Reply #4 on: August 17, 2015, 02:42:06 PM »
Hi,

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

 Bye,

 Jean

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • Flashing Lights
Re: get n-th parent
« Reply #5 on: August 17, 2015, 02:48:13 PM »
It comes by default in Playmaker

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: get n-th parent
« Reply #6 on: August 17, 2015, 04:56:48 PM »
ah!

learning everyday, thanks :)

Bye,

 Jean