PlayMaker Feedback > Action Requests
Help with a slight change of Simple Waypoint System action [SOLVED]
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: ---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); });
}
}
}
--- End code ---
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 :)
djaydino:
Hi.
Try this :
--- Code: --- [RequiredField]
[Tooltip("Receiver with the FSM event")]
[ObjectType(typeof(PlayMakerFSM))]
public FsmObject fsmReceiver;
--- End code ---
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 :)
Fat Pug Studio:
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); });
}
}
}
djaydino:
Hi.
Oops, i was very tired i guess.
I did not notice the script.
Can you try if the below works :
--- Code: ---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); });
}
}
}
--- End code ---
Fat Pug Studio:
Thanks, i'll try it out and let you know :)
Navigation
[0] Message Index
[#] Next page
Go to full version