playMaker

Author Topic: Can you get a nested field/property on a script?  (Read 677 times)

FedoraLord

  • Playmaker Newbie
  • *
  • Posts: 2
Can you get a nested field/property on a script?
« on: December 02, 2020, 10:49:15 PM »
Hi - I'm a seasoned programmer and Unity developer, but a noob to Playmaker. I need to call a method from a script field. The C# syntax for this would just be:

     character.characterLocomotion.SetTarget(someTransform);

So, I have a "Character" script, which has a field of the type "CharacterLocomotion", and that locomotion field has the method I need to call, not the character script.

Is there any way to traverse down nested object types like this with the built-in Playmaker actions? I would rather not have to write custom actions just to call a single method.

Also I don't want to modify the existing script because it comes from the Game Creator asset store package.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Can you get a nested field/property on a script?
« Reply #1 on: December 03, 2020, 08:50:33 AM »
Hi.
There are 2 actions that could help : Call Method or Call Static Method

But its very simple to make a custom action for it.

it would look something like this :

Code: [Select]
using UnityEngine;
using character

namespace HutongGames.PlayMaker.Actions
{

    [ActionCategory("Character")]
    public class CharacterLocomotionSetTarget : FsmStateAction
    {
        [RequiredField]
        public FsmOwnerDefault gameObject;

        public FsmFloat someTransform;

        // Code that runs on entering the state.
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null) return;

            go.characterLocomotion.SetTarget(someTransform.Value);
            Finish();
        }
    }
}

Here is also a link to the playmaker api :
https://hutonggames.fogbugz.com/default.asp?W127

FedoraLord

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Can you get a nested field/property on a script?
« Reply #2 on: December 03, 2020, 05:47:02 PM »
Thanks for the reply. I guess to get the exact functionality I'm looking for in the GUI I'd have to make a custom action and read the fields at runtime with System.Reflection

Nice game btw, I recognized it from the trailer. Just wishlisted it ;)