Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Rebooter on April 11, 2019, 01:04:01 AM
-
I tried modifying an action to get all Rigidbodies in children from a gameobject, but it is just returning an empty array. I have an array variable of array type 'Object' with object type 'Rigidbody', and the gameobject is set to the root bone of a model.
Would anyone know why this does not work?
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Gets all rigidbodies on gameobject and its children recursively.")]
public class GetAllRigidBodiesInChildren : FsmStateAction
{
[RequiredField]
[Tooltip("The GameObject to get recursive children from.")]
public FsmOwnerDefault gameObject;
[Tooltip("if true, will list inactive gameobjects")]
public FsmBool includeInactive;
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The Array Variable.")]
public FsmArray array;
private GameObject _go;
private Rigidbody[] _result;
public override void Reset()
{
gameObject = null;
includeInactive = false;
array = null;
}
public override void OnEnter()
{
Find();
Finish();
}
void Find()
{
_go = Fsm.GetOwnerDefaultTarget(gameObject);
if (_go == null)
{
return;
}
_result = _go.GetComponentsInChildren<Rigidbody>(includeInactive.Value);
array.RawValue = _result;
}
}
}
-
Hi,
setting array is tricky, I think you need to call .SaveChanges() on your array
if that doesn't work on it own, try to resize the array to the right value and set each indexes manually in a for loop.
or try to set the.ObjectReferences property instead of .rawvalue
let me know if you can't get it to work still...
bye,
Jean