playMaker

Author Topic: Help with a slight change of Simple Waypoint System action [SOLVED]  (Read 130 times)

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 828
    • View Profile
    • Fat Pug Studio
Hi guys,

i don't know if anyone's using the Simple Waypoint System plugin (i heartly recommend it), but i have an issue with one of the actions. Apparently, by popular demand, instead of choosing the game object that should receive the event by referencing the game object/fsm variable, it is a drag and drop field for the game object instance, which is silly and cannot be used properly.



Here's the code, it's quite small:

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using SWS;

//implements a PlayMaker FSM method call via event insert
namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Simple Waypoint System")]
    [Tooltip("Adds an event to a walker object for calling your own FSM state at waypoints.")]
    public class SWS_AddEventAtWaypoint : FsmStateAction
    {
        [RequiredField]
        [Tooltip("Walker object")]
        public FsmOwnerDefault walkerObject;

        [UIHint(UIHint.FsmInt)]
        [Tooltip("Waypoint index")]
        public FsmInt wpIndex;

        [RequiredField]
        [UIHint(UIHint.FsmGameObject)]
        [Tooltip("Receiver with the FSM event")]
        public PlayMakerFSM fsmReceiver;

        [RequiredField]
        [UIHint(UIHint.FsmString)]
        [Tooltip("Receiver FSM event to call")]
        public FsmString fsmEvent;


        public override void Reset()
        {
            walkerObject = null;
            wpIndex = null;
            fsmReceiver = null;
            fsmEvent = null;

        }


        public override void OnEnter()
        {
            Execute();

            Finish();
        }


        void Execute()
        {
            var go = Fsm.GetOwnerDefaultTarget(walkerObject);
            if (go == null) return;

            List<UnityEvent> events = null;

            splineMove spline = go.GetComponentInChildren<splineMove>();
            if (spline)
                events = spline.events;
            else
            {
                navMove nav = go.GetComponentInChildren<navMove>();
                if (nav)
                    events = nav.events;
            }

            UnityEvent myEvent = events[wpIndex.Value];
            myEvent.AddListener(delegate { fsmReceiver.SendEvent(fsmEvent.Value); });

        }
    }
}

This is the culprit: 

[RequiredField]
[UIHint(UIHint.FsmGameObject)]
[Tooltip("Receiver with the FSM event")]
public PlayMakerFSM fsmReceiver

I tried messing around by trying to insert stuff from send event action, but i'm not quite good with Playmaker API, i'd appreciate some help :)
« Last Edit: November 07, 2018, 05:58:09 AM by krmko »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Help with a slight change of Simple Waypoint System action
« Reply #1 on: November 02, 2018, 01:53:57 PM »
Hi.

Try this :

Code: [Select]
        [RequiredField]
        [Tooltip("Receiver with the FSM event")]
        [ObjectType(typeof(PlayMakerFSM))]
        public FsmObject fsmReceiver;

But you probably need to change something else further down in the script.

if so, can you paste the complete script so i can have a look :)

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 828
    • View Profile
    • Fat Pug Studio
Re: Help with a slight change of Simple Waypoint System action
« Reply #2 on: November 03, 2018, 12:39:47 AM »
That's the whole code, up there in the code box. Stays the same when i change it the way you advised.

It tried changing it to FsmGameObject but then i get the error further down the line:

'FsmGameObject' does not contain a definition for 'SendEvent' and no extension method 'SendEvent' accepting a first argument of type 'FsmGameObject' could be found (are you missing a using directive or an assembly reference?)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using SWS;

//implements a PlayMaker FSM method call via event insert
namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Simple Waypoint System")]
    [Tooltip("Adds an event to a walker object for calling your own FSM state at waypoints.")]
    public class SWS_AddEventAtWaypoint : FsmStateAction
    {
        [RequiredField]
        [Tooltip("Walker object")]
        public FsmOwnerDefault walkerObject;

        [UIHint(UIHint.FsmInt)]
        [Tooltip("Waypoint index")]
        public FsmInt wpIndex;

        [RequiredField]
        [UIHint(UIHint.FsmGameObject)]
        [Tooltip("Receiver with the FSM event")]
        public PlayMakerFSM fsmReceiver;

        [RequiredField]
        [UIHint(UIHint.FsmString)]
        [Tooltip("Receiver FSM event to call")]
        public FsmString fsmEvent;
      

        public override void Reset()
        {
            walkerObject = null;
            wpIndex = null;
            fsmReceiver = null;
            fsmEvent = null;

        }


        public override void OnEnter()
        {
            Execute();

            Finish();
        }


        void Execute()
        {
            var go = Fsm.GetOwnerDefaultTarget(walkerObject);
            if (go == null) return;

            List<UnityEvent> events = null;

            splineMove spline = go.GetComponentInChildren<splineMove>();
            if (spline)
                events = spline.events;
            else
            {
                navMove nav = go.GetComponentInChildren<navMove>();
                if (nav)
                    events = nav.events;
            }

            UnityEvent myEvent = events[wpIndex.Value];
            myEvent.AddListener(delegate { fsmReceiver.SendEvent(fsmEvent.Value); });

        }
    }
}
« Last Edit: November 03, 2018, 12:53:47 AM by krmko »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: Help with a slight change of Simple Waypoint System action
« Reply #3 on: November 04, 2018, 02:17:40 PM »
Hi.
Oops, i was very tired i guess.
I did not notice the script.

Can you try if the below works :
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using SWS;

//implements a PlayMaker FSM method call via event insert
namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Simple Waypoint System")]
    [Tooltip("Adds an event to a walker object for calling your own FSM state at waypoints.")]
    public class SWS_AddEventAtWaypoint : FsmStateAction
    {
        [RequiredField]
        [Tooltip("Walker object")]
        public FsmOwnerDefault walkerObject;

        [UIHint(UIHint.FsmInt)]
        [Tooltip("Waypoint index")]
        public FsmInt wpIndex;

        [RequiredField]
        [Tooltip("Receiver with the FSM event")]
        [ObjectType(typeof(PlayMakerFSM))]
        public FsmObject fsmReceiver;

        [RequiredField]
        [UIHint(UIHint.FsmString)]
        [Tooltip("Receiver FSM event to call")]
        public FsmString fsmEvent;

        private PlayMakerFSM theFsmReceiver;

        public override void Reset()
        {
            walkerObject = null;
            wpIndex = null;
            fsmReceiver = null;
            fsmEvent = null;

        }


        public override void OnEnter()
        {
            Execute();

            Finish();
        }


        void Execute()
        {
            theFsmReceiver = fsmReceiver.Value as PlayMakerFSM;
            var go = Fsm.GetOwnerDefaultTarget(walkerObject);
            if (go == null) return;

            List<UnityEvent> events = null;

            splineMove spline = go.GetComponentInChildren<splineMove>();
            if (spline)
                events = spline.events;
            else
            {
                navMove nav = go.GetComponentInChildren<navMove>();
                if (nav)
                    events = nav.events;
            }

            UnityEvent myEvent = events[wpIndex.Value];
            myEvent.AddListener(delegate { theFsmReceiver.SendEvent(fsmEvent.Value); });

        }
    }
}

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 828
    • View Profile
    • Fat Pug Studio
Re: Help with a slight change of Simple Waypoint System action
« Reply #4 on: November 05, 2018, 07:38:25 AM »
Thanks, i'll try it out and let you know :)

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 828
    • View Profile
    • Fat Pug Studio
Re: Help with a slight change of Simple Waypoint System action
« Reply #5 on: November 07, 2018, 05:57:28 AM »
Works like a charm. thanks, i learned something new :)