playMaker

Author Topic: Is this action generated by chat GPT correct?  (Read 389 times)

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Is this action generated by chat GPT correct?
« on: February 17, 2024, 03:58:25 PM »
Hi I asked chat GPT to create a action to get first active child of a game object. Is this correct?

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Finds the first active child of a GameObject.")]
    public class GetActiveChild : FsmStateAction
    {
        [RequiredField]
        [Tooltip("The GameObject to search.")]
        public FsmOwnerDefault gameObject;

        [UIHint(UIHint.Variable)]
        [Tooltip("Store the first active child in a GameObject variable.")]
        public FsmGameObject storeResult;

        public override void Reset()
        {
            gameObject = null;
            storeResult = null;
        }

        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                Finish();
                return;
            }

            foreach (Transform child in go.transform)
            {
                if (child.gameObject.activeInHierarchy)
                {
                    storeResult.Value = child.gameObject;
                    break;
                }
            }

            Finish();
        }
    }
}

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Is this action generated by chat GPT correct?
« Reply #1 on: February 18, 2024, 10:02:03 AM »
your store result can only hold 1 object.
so you would need to set an array since you can have multiple child objects