playMaker

Author Topic: Action to get all rigidbodies in children (not working)  (Read 79 times)

Rebooter

  • Playmaker Newbie
  • *
  • Posts: 1
    • View Profile
Action to get all rigidbodies in children (not working)
« on: April 10, 2019, 10:04:01 PM »
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;
        }
    }
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14058
  • Official Playmaker Support
    • View Profile
Re: Action to get all rigidbodies in children (not working)
« Reply #1 on: April 10, 2019, 11:55:13 PM »
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