playMaker

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

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
    • View Profile
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, 11:32:51 AM by Grofit »

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
    • View Profile
Re: Event not used by this state or any global transition error
« Reply #1 on: January 16, 2013, 08: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: 3581
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Event not used by this state or any global transition error
« Reply #2 on: January 16, 2013, 10:26:01 AM »
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
    • View Profile
Re: Event not used by this state or any global transition error
« Reply #3 on: January 16, 2013, 11:32:35 AM »
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: 125
    • View Profile
    • Serenefox Games
Re: [SOLVED] Event not used by this state or any global transition error
« Reply #4 on: April 20, 2016, 11:42:19 PM »
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:
Don't Pop! Dungeon - iOS/Android