playMaker

Author Topic: Transition event doesn't fire in delegate function?  (Read 2259 times)

deepcanvas

  • Playmaker Newbie
  • *
  • Posts: 7
Transition event doesn't fire in delegate function?
« on: May 19, 2013, 06:04:29 AM »
Having trouble getting delegate functions to fire events: So I've setup delegates in a separate class; this is working fine as I can see my function FinishedDelegate() in my custom action is called at the expected time as it writes the expected lines to the log.

However, for some reason the transition event I'm trying to call does not fire... I don't understand why, as the surrounding lines of code obviously do get called. If I fire the event within my OnEnter() function the event fires, just not from within the FinishedDelegate() function.

Here's the relevant piece of code from my custom action:

Code: [Select]
    public FsmEvent finishedEvent;

    public override void OnEnter()
    {
        SomeClass someClass = SomeClass.Exec();

        if (finishedEvent != null)
        {
            someClass.FinishedDelegate = FinishedDelegate;

            // Fsm.Event(finishedEvent); // <- this works!
        }
    }

    void FinishedDelegate()
    {
        Debug.Log("before!"); // writes to log
        Fsm.Event(finishedEvent); // <- does nothing??
        Debug.Log("after!"); // writes to log
    }

Any idea why finishedEvent is never fired?

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Transition event doesn't fire in delegate function?
« Reply #1 on: May 20, 2013, 01:41:16 AM »
Hi,

 I would file a bug report for this.

 meanwhile, I would raise a flag, and on the OnUpdate, I would check for it and fire the event from the regular overrides methods. It may be a limitation, or maybe your delegate is called within a different thread or something that prevents events to be fired somehow.

bye,

 Jean

deepcanvas

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Transition event doesn't fire in delegate function?
« Reply #2 on: May 21, 2013, 06:02:33 AM »
Good point about the separate thread. I'll run some tests to see whether I can get the event to fire in a single-threaded model, though I suspect that would make my program design problematic.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Transition event doesn't fire in delegate function?
« Reply #3 on: May 21, 2013, 07:49:41 AM »
Hi,

 Don't change the way the delegate is fired, simply change the way the custom actions process it, that's easier for sure. I implemented this bool flag indirection level and it works very well. Anything can be achieved like so, and you completly remove all threading problems within the custom action.

bye,

 Jean