playMaker

Author Topic: [SOLVED] Event not used by this state or any global transition error  (Read 6602 times)

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
Quick question, I have an action as shown below:

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

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Gets all game objects within a given spherical radius and sends an event to them.")]
public class SendEventToGameObjectsWithinRadius : FsmStateAction
{
[RequiredField]
[Tooltip("The owner object.")]
public FsmOwnerDefault gameObject;

        [UIHint(UIHint.FsmFloat)]
[Tooltip("The radius to search for objects within.")]
public FsmFloat radius;

[UIHint(UIHint.Tag)]
[Tooltip("Tagged objects to use.")]
public FsmString tag;

        [RequiredField]
        [Tooltip("Event to raise on objects.")]
        public FsmEvent eventToRaise;

public override void Reset()
{
            gameObject = null;
radius = 10.0f;
            tag = string.Empty;
   eventToRaise = null;
}

public override void OnEnter()
{
var underlyingGameObject = Fsm.GetOwnerDefaultTarget(gameObject);
IEnumerable<Collider> colliders = Physics.OverlapSphere(underlyingGameObject.transform.position, radius.Value);

   if(!string.IsNullOrEmpty(tag.Value))
{ colliders = colliders.Where(x => x.tag.Equals(tag.Value)); }

            foreach (var collider in colliders)
            {
                var fsmComponent = collider.GetComponent<PlayMakerFSM>();
if(fsmComponent != null) { fsmComponent.Event(eventToRaise); }
            }
}
}
}

So basically find all elements of a given type near the owner object, and send an event to them. This is used in situations like an explosion happening and notifying nearby entities. As the event is not used on the owner object it seems like Playmaker does not like this and raises the error as titled. Now I can understand why it tells you this as in some cases you could be firing events that are not used, however I see this as a warning not an error, and in this case the event is used to relay to other objects. I have attached an image of the error.

So is there a way to stop this error from happening, as it seems like a legitimate use case.
« Last Edit: January 16, 2013, 01:32:51 PM by Grofit »

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
Re: Event not used by this state or any global transition error
« Reply #1 on: January 16, 2013, 10:49:29 AM »
Didnt really want to bump, but this is a bit of a blocker at the moment as I cannot run the project until this error has been fixed, but not really sure what playmaker wants me to do.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Event not used by this state or any global transition error
« Reply #2 on: January 16, 2013, 12:26:01 PM »
That error is indeed a false positive. I'll add a NoErrorCheck attribute for such cases...

However this Playmaker error shouldn't stop you from compiling in Unity...? Are you finding that it does?

If you don't want to see the Playmaker error you could add an FsmEventTarget parameter as a temporary workaround to fool the error checker! Example:

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

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.GameObject)]
    [Tooltip("Gets all game objects within a given spherical radius and sends an event to them.")]
    public class SendEventToGameObjectsWithinRadius : FsmStateAction
    {
        public FsmEventTarget eventTarget = new FsmEventTarget();

        [RequiredField]
        [Tooltip("The owner object.")]
        public FsmOwnerDefault gameObject;

        [UIHint(UIHint.FsmFloat)]
        [Tooltip("The radius to search for objects within.")]
        public FsmFloat radius;

        [UIHint(UIHint.Tag)]
        [Tooltip("Tagged objects to use.")]
        public FsmString tag;

        [RequiredField]
        [Tooltip("Event to raise on objects.")]
        public FsmEvent eventToRaise;

        public override void Reset()
        {
            eventTarget.target = FsmEventTarget.EventTarget.BroadcastAll;
            gameObject = null;
            radius = 10.0f;
            tag = string.Empty;
            eventToRaise = null;
        }

        public override void OnEnter()
        {
            var underlyingGameObject = Fsm.GetOwnerDefaultTarget(gameObject);
            IEnumerable<Collider> colliders = Physics.OverlapSphere(underlyingGameObject.transform.position, radius.Value);

            if (!string.IsNullOrEmpty(tag.Value))
            { colliders = colliders.Where(x => x.tag.Equals(tag.Value)); }

            foreach (var collider in colliders)
            {
                var fsmComponent = collider.GetComponent<PlayMakerFSM>();
                if (fsmComponent != null) { fsmComponent.Fsm.Event(eventToRaise); }
            }
        }
    }
}


This shouldn't effect the behaviour of the action. But I haven't tested it :)

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
Re: Event not used by this state or any global transition error
« Reply #3 on: January 16, 2013, 01:32:35 PM »
Sorry in my haste last night I didnt realise I had made a refactor which was using fsmComponent.Event(someEvent) rather than fsmComponent.SendEvent(someEvent.Name). If I was in Visual Studio it would have shown be right away but MonoDevelop didnt really tell me so I was assuming it was the other error which was to do with events.

Will mark it as solved now, thanks!

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Re: [SOLVED] Event not used by this state or any global transition error
« Reply #4 on: April 21, 2016, 02:42:19 AM »
I know this topic is old but, is there anyway to convert the above code to work with 2d physics? I have been trying to do this for 3 hours now with very little luck.
Most Recent Published Games:
Juicy Theater - Android

acknickulous

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Event not used by this state or any global transition error
« Reply #5 on: June 17, 2019, 02:10:03 AM »
Thread necro--I have this same error with this action, any idea why?  I made this simple action to send events to the children of an object. It runs fine but I get this error in the PlayMaker editor. I'd like to eliminate it.

Code: [Select]
using HutongGames.PlayMaker;
using UnityEngine;
using PathologicalGames;

[ActionCategory(ActionCategory.GameObject)]
[HutongGames.PlayMaker.Tooltip("sends a message to first depth level children")]
public class broadcastToChildren : FsmStateAction
{
    [UIHint(UIHint.Variable)]
    public FsmOwnerDefault gameObject;

    public FsmBool everyFrame;
    public FsmBool includeInactive;

    public FsmEvent eventToSend;

    //public FsmString eventName;

    GameObject _go;
    PlayMakerFSM[] _p;

    // Code that runs on entering the state.

    public override void OnEnter()
    {
        _go = Fsm.GetOwnerDefaultTarget(gameObject);

        SendEvents();

        Finish();
    }

    public override void OnUpdate()
    {
        if (!everyFrame.Value)
            return;

        SendEvents();
    }

    void SendEvents()
    {
        if (_go == null)
            return;

        GameObject g;

        for (int i = 0; i < _go.transform.childCount; i++)
        {
            g = _go.transform.GetChild(i).gameObject;

            if (!includeInactive.Value && !g.activeInHierarchy)
                continue;

            Fsm.BroadcastEventToGameObject(g, eventToSend.Name, false, false);
        }
    }


}
« Last Edit: June 17, 2019, 02:26:24 AM by acknickulous »