Forums › 💬 FlowCanvas › ⚙️ Support › Trying to recieve/listen for UnityEvent
Hi,
Is it possible to recieve a Unity Event?
http://docs.unity3d.com/ScriptReference/Events.UnityEvent.html
I have a script that calls an event when done, and would like Flow Canvas to listen for it?
I’ve tried all sorts tonight and just can’t get it. Is it even possible?
Here is an example of the script:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using UnityEngine; using System.Collections.Generic; using MovementEffects; using NodeCanvas.Framework; using UnityEngine.Events; public class CustomWait : MonoBehaviour { public Blackboard DialBlackboard; public UnityEvent finishedCountdown; public float duration; public float timer; void Start() { if (finishedCountdown == null) { finishedCountdown = new UnityEvent(); } } public void StartTimer() { Timing.RunCoroutine(StartCountdown()); } IEnumerator<float> StartCountdown() { timer = duration; while (timer > 0) { timer -= Time.deltaTime; DialBlackboard.SetValue("Current Cooldown", timer); yield return 0f; } DialBlackboard.SetValue("Current Cooldown", 0f); finishedCountdown.Invoke(); yield return 0f; } } |
Thanks!
Hi again,
I’ve also tried using the Flow Canvas event, but can only seem to access sendglobalevent not sendevent. It says in the node help to use SendEvent.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
using UnityEngine; using System.Collections.Generic; using MovementEffects; using NodeCanvas.Framework; using UnityEngine.Events; using FlowCanvas; public class CustomWait : MonoBehaviour { public Blackboard DialBlackboard; public UnityEvent finishedCountdown; public float duration; public float timer; void Start() { if (finishedCountdown == null) { finishedCountdown = new UnityEvent(); } } public void StartTimer() { Timing.RunCoroutine(StartCountdown()); } IEnumerator<float> StartCountdown() { timer = duration; while (timer > 0) { timer -= Time.deltaTime; DialBlackboard.SetValue("Current Cooldown", timer); yield return 0f; } DialBlackboard.SetValue("Current Cooldown", 0f); FlowScriptController.SendGlobalEvent("test"); //FlowScriptController.SendEvent("test"); << SendEvent does not show up in intellisense either finishedCountdown.Invoke(); yield return 0f; } } |
Hey,
I’m not sure how it’s possible that you can’t use the SendEvent, or why it doesn’t show in the intellisense , but it’s certainly there 🙂
It can also be used with the Unity event in the inspector:
[attachment file=”UnityEvent.png”]
And then you can simply use the node “Events/Script/Custom Event”
[attachment file=”UnityEvents2.png”]
Let me know a bit more info if possible on why this can’t be done in your case.
Thank you.
Hi,
Here is an example of trying to only use Send Event. Am I doing something wrong?
[attachment file=”634″]
It only showing SendGlobalEvent and is not accessible even when typed. This is in a new project by the way.
Hey,
The reason why intellisense is not showing you the SendEvent and it’s rather showing you the static SendGlobaEvent only, is because, you have entered the type name ‘FlowScriptController’, and not an instance reference to it 🙂 As such, only static members/methods are shown there. What you need is an instance reference. Here is an example:
|
1 2 3 4 5 6 7 |
void OnEnable(){ var fsController = GetComponent<FlowScriptController>(); fsController.SendEvent("MyEvent"); } |
Let me know if that works for you.
Thanks.
Sorry, I was being code blind on that one. It works great. Thank you!
