Events/Signals as global from code?

Slate Forums General Discussion Events/Signals as global from code?

This topic contains 1 reply, has 2 voices, and was last updated by  Gavalakis 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #2222


    I used the unity forums link and got here, now I see it is the wrong forum entirely… can you move it to the NC forum?


    Hey! Discovering NC now but I find it’s got a pretty steep learning curve.

    What I’m trying to do: my DefenderAgent has a parallel task that checks if any enemies entered its trigger.
    If so, it is added to a list of Targets. Then shoots at it.

    Now, my idea was that when the enemy is dead, it sends either a Signal or Event. I went with Event for now. That’s cool, I can check global and the FSM of my DefenderAgent removes the enemy from the Targets list (in the parallel task).

    I also have some bounds in my scene that if the Defender doesn’t kill the enemy the enemy dies on hitting the bounds and well, damages the player or deducts score, whatever. When the bound is hit, it despawns the enemy from the scene with a Pooling manager. In the OnDespawned function of my enemy I want the DefenderAgent to know that the enemy died due to ‘external causes’. So I thought I’d do this from code:

    GetComponent<GraphOwner>().SendEvent(“EnemyDeath”, null, gameObject);

    But that doesn’t emit it globally. So question would be: how can I let my DefenderAgent FSM best know the enemy that was in its TargetList is dead and should be removed from the list? Am I totally going about this the wrong way? A global event would already help I guess, but how? Also wanted to try Signals but tbh I can’t really find how to send those from the code… if you could help me out, thanks!

    P.S. If you see weird things that I could do much easier, please feel free to advise. The idea is: Defender sees enemies in its trigger, picks the closest and fires on it. I’m debating whether I want to pick a new target after a few seconds to re-evaluate the biggest threat or only after the picked target died but that’s for later.


    You must be logged in to view attached files.


    Hello there,

    I cant move the post to NC (somewhat different databases), but I will answer your question here, no problem 🙂

    So, to send a global event you simply need to use the static method Graph.SendGlobalEvent (same arguments as SendEvent) instead of the instance method found on GraphOwner.

    For Signals, it is a bit different. You need to get a reference to the SignalDefinition (the scriptable object) and then call the instance method in it Invoke. Regarding the parameters,
    sender -> just a reference to a sender transform; not very important unless expected.
    receiver -> null if you are going to invoke signal as global, otherwise the transform that should be awaiting the signal event (has already subscribed).
    isGlobal -> true or false as appropriate.
    args -> the signal event arguments. Should match the same length and type in order of appearance as the parameters defined in the Signal Definition inspector.

    Please let me know if the above works for you 🙂

    Join us on Discord:

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.