playMaker

Author Topic: Problem with custom sendEvent action and the "FsmEvent" type.  (Read 2602 times)

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Problem with custom sendEvent action and the "FsmEvent" type.
« on: December 10, 2013, 10:50:41 AM »
Hi,

we use a similar logic to the ArrayMaker addon for PM, but as a general component also use-able from script. We call this "gameobject links" and u can perform certain actions using those editor setup links.

While trying to create a "SendEventToLinked" action, i noticed that the "FsmEvent" type has some special logic tied up regarding the existence of a "FsmEventTarget" field inside a action?

It seems that by default the editor looks for those types and automatically ties them up, so if u select a external gameobject/fsm it shows only global events, while if selected self or similar, it will list only local events in the event dropdown.
While this logic is fine in itself, it looks specially hardcoded, since i cant see any special attribute that would link a FsmEvent field to a FsmEventTarget field, yet  just adding a field changes the behavior?

Is there a way to manually override this logic or tie it up to a FsmOwnerDefault type? The problem is in our case, it makes no sense to have to full FsmEventTarget options visible/selectable, since the target object is just the object that has the "link" component to-be used?

We would like to use PM default SendEventToFsmOnGameObject() call, so all the eventdata and check options for a normal FsmEvent are available/setup.


Thx Andy


PS: I tried to reset the Event field to:
Code: [Select]
sendEvent = new FsmEvent("") {IsGlobal = true};but i still don't get a drop-down list of all available global events?

We also get a "Event not used by this state or any global transition!" error, which seems to indicate that maybe FsmEvent is not designed in a way that it can be used as standalone type? This error message also seem to indicate some special logic regarding the Event type, since its not inside the ErrorCheck() call? Is there a way to disable this error check?
« Last Edit: December 10, 2013, 11:59:07 AM by Andy22 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with custom sendEvent action and the "FsmEvent" type.
« Reply #1 on: December 10, 2013, 01:57:47 PM »
Hi,

If I understand correctly your struggle, I think what you want to achieve is to send an event to a game object, right?

 I have this, this may contains some hints on how to solve your problem.


Code: [Select]
public static void SendEventToGameObject(PlayMakerFSM fromFsm,GameObject target,string fsmEvent,FsmEventData eventData)
{
if (eventData!=null)
{
HutongGames.PlayMaker.Fsm.EventData = eventData;
}

FsmEventTarget _eventTarget = new FsmEventTarget();
_eventTarget.excludeSelf = false;
FsmOwnerDefault owner = new FsmOwnerDefault();
owner.OwnerOption = OwnerDefaultOption.SpecifyGameObject;
owner.GameObject = new FsmGameObject();
owner.GameObject.Value = target;
_eventTarget.gameObject = owner;
_eventTarget.target = FsmEventTarget.EventTarget.GameObject;

_eventTarget.sendToChildren = false;

fromFsm.Fsm.Event(_eventTarget,fsmEvent);
}

Bye,

 Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Problem with custom sendEvent action and the "FsmEvent" type.
« Reply #2 on: December 11, 2013, 05:32:46 AM »
Yes i found the SendEventToGameObject() too, i was just hoping i can directly use a FsmEvent via editor setup, instead of a string + FsmEventData.

The problem is that u only can setup/see local event's, without also using a FsmEventTarget field, which limits the use of the FsmEvent type a bit.
It would help if i could bind the FsmEvent editor logic via a custom attribute to a gameobject of my choice, so it can work with FsmOwnerDefault as example.
Alternatively a way to configure the editor display of FsmEvent in a more custom way.

bye Andy
« Last Edit: December 11, 2013, 05:34:36 AM by Andy22 »

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Problem with custom sendEvent action and the "FsmEvent" type.
« Reply #3 on: January 07, 2014, 09:59:51 AM »
We still have this problem, there seems quite some special logic inside the editor that handles what is shown in the FsmEvent drop-down list. From testing, i could gather that u either need a "Set Event Target" action in front of the "next" action that uses a FsmEvent member field or u need a "public FsmEventTarget" member field before the FsmEvent field in the same action.

The problem for our custom action is, that the "event target" is a array of gameobjects. So we cant use the default "FsmEventTarget" object and we also cant extent it.

The only hack we came up with is to use a "public FsmEventTarget" and init it to "BroadcastAll". This way the following FsmEvent field will show all global events, unfortunately we cant set this field to protected/private.

We would like a attribute, that can steer/override the way the drop-down is shown for a FsmEvent field inside a action, where no clear single event-target exists.

Thx Andy
« Last Edit: January 07, 2014, 10:02:08 AM by Andy22 »