playMaker

Author Topic: Sending Event with Script not working  (Read 2789 times)

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Sending Event with Script not working
« on: August 08, 2019, 03:17:02 AM »
Hello guys,

I am trying to send event through scripting but it doesn't seem to trigger in the FSM.

Code: [Select]
    public void EndTurn()
    {

        GameObject gameManager = GameObject.FindGameObjectWithTag("Game Manager");

        PlayMakerFSM gameManagerFSM = PlayMakerFSM.FindFsmOnGameObject(gameManager, "Turn Manager");
        PlayMakerUtils.SendEventToGameObject(gameManagerFSM, gameManager, "Manually End Player Turn");

        Debug.Log("Called " + gameManager + " " + gameManagerFSM);
    }

The debug log fires but the fsm event does not. I checked the spelling of the event too.

Thanks,
jrDev
« Last Edit: August 08, 2019, 03:25:01 AM by jrDev »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Sending Event with Script not working
« Reply #1 on: August 08, 2019, 05:21:15 AM »
Hi.

Try this :

Code: [Select]
        PlayMakerFSM gameManagerFSM = PlayMakerFSM.FindFsmOnGameObject(go, "FSM");
        gameManagerFSM.Fsm.Event("Redeem");

If the script is in the scene from the start you can set a public variable for the fsm.

if not, you might want to place the FindGameObjectWithTag and FindFsmOnGameObject.
in a OnEnable()

here is a sample where you can drag the fsm in directly :

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker;

public class test : MonoBehaviour
{
    public PlayMakerFSM gameManagerFSM;

    public void EndTurn()
    {
        gameManagerFSM.Fsm.Event("Manually End Player Turn");
    }
}

To drag the fsm from another object, you can lock the inspector (top right)

then add a new inspector tab (click next to lock and select 'add tab' / Inspector)
then drag it somewhere so you can see both.

drag fsm to script.

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Re: Sending Event with Script not working
« Reply #2 on: August 08, 2019, 10:10:04 PM »
Hi.

Try this :

Code: [Select]
        PlayMakerFSM gameManagerFSM = PlayMakerFSM.FindFsmOnGameObject(go, "FSM");
        gameManagerFSM.Fsm.Event("Redeem");

If the script is in the scene from the start you can set a public variable for the fsm.

if not, you might want to place the FindGameObjectWithTag and FindFsmOnGameObject.
in a OnEnable()

here is a sample where you can drag the fsm in directly :

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker;

public class test : MonoBehaviour
{
    public PlayMakerFSM gameManagerFSM;

    public void EndTurn()
    {
        gameManagerFSM.Fsm.Event("Manually End Player Turn");
    }
}

To drag the fsm from another object, you can lock the inspector (top right)

then add a new inspector tab (click next to lock and select 'add tab' / Inspector)
then drag it somewhere so you can see both.

drag fsm to script.

Hello,

What I posted in the original post actually worked. I just seemed to have hit a bug in Playmaker that keeps reference to Phantom Events. That same "Manually End Turn"  event was removed for some reason I cant remember, but I re-added a new one of this event with the same name. After looking through the Events tab, I noticed there was 2 of the same Events saved which I assume is a bug because you can't (shouldn't?) be able to have global events with the same name. This seems to have cause the issue cause as soon as I removed one of the Events my script started to work. See attached pic below. Should this be reported?
« Last Edit: August 08, 2019, 10:12:23 PM by jrDev »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Sending Event with Script not working
« Reply #3 on: August 09, 2019, 06:57:53 AM »
Hi.
You can report the issue in the bug report section or thru the asset (playmaker/tools/submit bug report)

if you could try to repo how the duplicate got there, it would be very helpful.

What unity/playmaker version are you using?

Also did you do an update on unity or playmaker.

Was the old removed one possibly on a prefab?

any more information you can think of, please share.

It can be helpful to narrow down the issue.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending Event with Script not working
« Reply #4 on: August 12, 2019, 05:08:52 AM »
Hi,

 are you you don't have a space or a tab character at the end of one of these duplicate event? turn the global flag off and you can edit the name, check then.

like
"My Event "
"My Event"

the extra space char will not be seen in this UI.

Let me know if they are exactly the same strings

Bye,

 Jean