Forums › 💬 NodeCanvas › ⚙️ Support › Action doesn't wait for Coroutine end (IEnumerator) to finish › Reply To: Action doesn't wait for Coroutine end (IEnumerator) to finish
So I’ve been trying to get this to work and I’m having no luck at all. Hopefully I’m missing something obvious but I fear that NC is pretty broken with coroutines and C# events in it’s current state.
So I have the below test script attached to a cube as well as the FSM below. The script runs and executes the initial wait action and then moves to the next action but simply executes the method and immediately goes green, never catching the event that should cause the FSM to change states. In NC1, the state would remain yellow in the graph until the coroutine finished. Then it would move on if any conditions had been met.
|
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 |
using System; using UnityEngine; using System.Collections; public class TestScript : MonoBehaviour { public delegate void EmptyEventHandler(); public event Action UnDocked; public event Action Docked; public event Action StartUp; public float _timer; public void Update() { _timer = _timer + Time.deltaTime; } public IEnumerator Test2SecondCoRoutine() { while (_timer <= Time.deltaTime + 2f) { //yield return null; } Debug.Log("2 seconds have passed."); _timer = 0f; if (Docked != null) Docked(); yield return null; } public IEnumerator Test1SecondCoRoutine() { while (_timer <= Time.deltaTime + 1f) { //yield return null; } Debug.Log("1 second has passed."); _timer = 0f; if (UnDocked != null) UnDocked(); yield return null; } } |
Here is the FSM export.
{
“version”: 2.0,
“type”: “NodeCanvas.StateMachines.FSM”,
“name”: “FSM”,
“comments”: “”,
“translation”: {
“x”: -5171.998046875,
“y”: -4822.998046875
},
“nodes”: [
{
“_actionList”: {
“executionMode”: “ActionsRunInParallel”,
“actions”: [
{
“waitTime”: {
“_value”: 2.0,
“_name”: null
},
“finishStatus”: “Success”,
“_isActive”: true,
“overrideAgent”: null,
“$type”: “NodeCanvas.Tasks.Actions.Wait”
}
],
“_isActive”: true,
“overrideAgent”: null
},
“_repeatStateActions”: false,
“_transitionEvaluation”: “CheckContinuously”,
“_collapsed”: false,
“_position”: {
“x”: 5430.0,
“y”: 5040.0
},
“_name”: null,
“_tag”: null,
“_comment”: null,
“_isBreakpoint”: false,
“$type”: “NodeCanvas.StateMachines.ActionState”,
“$id”: “1”
},
{
“_actionList”: {
“executionMode”: “ActionsRunInParallel”,
“actions”: [
{
“functionWrapper”: {
“result”: {
“_value”: null,
“_name”: “”
},
“_targetMethod”: {
“_baseInfo”: “TestScript|Test2SecondCoRoutine”,
“_paramsInfo”: “”
},
“$type”: “NodeCanvas.Framework.Internal.ReflectedFunction1[[System.Collections.IEnumerator, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”1[[System.Collections.IEnumerator, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”
},
“_isActive”: true,
“overrideAgent”: null,
“$type”: “NodeCanvas.Tasks.Actions.ExecuteFunction”
}
],
“_isActive”: true,
“overrideAgent”: null
},
“_repeatStateActions”: false,
“_transitionEvaluation”: “CheckContinuously”,
“_collapsed”: false,
“_position”: {
“x”: 5580.0,
“y”: 5220.0
},
“_name”: null,
“_tag”: null,
“_comment”: null,
“_isBreakpoint”: false,
“$type”: “NodeCanvas.StateMachines.ActionState”,
“$id”: “5”
},
{
“_actionList”: {
“executionMode”: “ActionsRunInParallel”,
“actions”: [
{
“functionWrapper”: {
“result”: {
“_value”: null,
“_name”: “”
},
“_targetMethod”: {
“_baseInfo”: “TestScript|Test1SecondCoRoutine”,
“_paramsInfo”: “”
},
“$type”: “NodeCanvas.Framework.Internal.ReflectedFunction
},
“_isActive”: true,
“overrideAgent”: null,
“$type”: “NodeCanvas.Tasks.Actions.ExecuteFunction”
}
],
“_isActive”: true,
“overrideAgent”: null
},
“_repeatStateActions”: false,
“_transitionEvaluation”: “CheckContinuously”,
“_collapsed”: false,
“_position”: {
“x”: 5835.0,
“y”: 5370.0
},
“_name”: “sdfsdf”,
“_tag”: null,
“_comment”: null,
“_isBreakpoint”: false,
“$type”: “NodeCanvas.StateMachines.ActionState”,
“$id”: “11”
}
],
“connections”: [
{
“_condition”: null,
“_infoExpanded”: true,
“_sourceNode”: {
“$ref”: “1”
},
“_targetNode”: {
“$ref”: “5”
},
“_isActive”: true,
“$type”: “NodeCanvas.StateMachines.FSMConnection”
},
{
“_condition”: {
“targetType”: “TestScript”,
“eventName”: “Docked”,
“_invert”: false,
“_isActive”: true,
“overrideAgent”: null,
“$type”: “NodeCanvas.Tasks.Conditions.CheckCSharpEvent”
},
“_infoExpanded”: true,
“_sourceNode”: {
“$ref”: “5”
},
“_targetNode”: {
“$ref”: “11”
},
“_isActive”: true,
“$type”: “NodeCanvas.StateMachines.FSMConnection”
},
{
“_condition”: {
“targetType”: “TestScript”,
“eventName”: “UnDocked”,
“_invert”: false,
“_isActive”: true,
“overrideAgent”: null,
“$type”: “NodeCanvas.Tasks.Conditions.CheckCSharpEvent”
},
“_infoExpanded”: true,
“_sourceNode”: {
“$ref”: “11”
},
“_targetNode”: {
“$ref”: “5”
},
“_isActive”: true,
“$type”: “NodeCanvas.StateMachines.FSMConnection”
}
],
“primeNode”: {
“$ref”: “1”
},
“canvasGroups”: null,
“localBlackboard”: {
“_name”: “Local Blackboard”,
“_variables”: [],
“$type”: “NodeCanvas.Framework.Internal.BlackboardSource”
}
}
