NodeCanvas Forums › Support › PauseBehavior() doesn't seem to work
Hey!
So, I want to be able to play and pause a behavior tree from another behavior tree and vice versa. I have two behaviour tree owners on a single gameobject and have the instances stored in a BTManager script on that gameobject. This works fine and is in the code that is attached. I am able to pause/play a BehaviorTree and it shows as such in the inspector (the play/pause button change), but the tree that is supposed to pause doesn’t pause. However, if I use “stopbehaviour()” that works fine… Thoughts?
Thanks!
C
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
using UnityEngine; using System.Collections; using System.Collections.Generic; using NodeCanvas.Framework; using NodeCanvas.BehaviourTrees; public class BTManager : MonoBehaviour { public BehaviourTreeOwner mainTreeOwner; public BehaviourTreeOwner secondaryTreeOwner; void Start() { List myOwner = new List(this.gameObject.GetComponentsInChildren()); if(myOwner[0]==null){ Debug.LogError("No Behaviour Tree Owners"); return; } if(myOwner.Count <2){ Debug.LogError("No Secondary Tree Owner"); return; } mainTreeOwner = myOwner[0]; secondaryTreeOwner = myOwner[1]; } public void PauseMainTree() { if(!mainTreeOwner.isPaused){ mainTreeOwner.PauseBehaviour(); Debug.Log("Pause Main Tree"); } else Debug.Log("Can't Pause Main Tree"); } public void StartMainTree() { if(mainTreeOwner.isPaused){ mainTreeOwner.StartBehaviour(); Debug.Log("Start Main Tree"); } else Debug.Log("Can't Start Main Tree"); } public void PauseSecondaryTree() { if(!secondaryTreeOwner.isPaused){ secondaryTreeOwner.PauseBehaviour(); Debug.Log("Pause Secondary Tree"); Debug.Log ("2ndary Tree isRunning: " + secondaryTreeOwner.isRunning); } else Debug.Log("Can't Pause Secondary Tree"); } public void StartSecondaryTree() { if(secondaryTreeOwner.isPaused){ secondaryTreeOwner.StartBehaviour(); Debug.Log("Start Secondary Tree"); Debug.Log ("2ndary Tree isRunning: " + secondaryTreeOwner.isRunning); } else Debug.Log("Can't Start Secondary Tree"); } } |
functions that I can call from within a behavior tree to pause/play particular trees.
and iterated through them using a Behavior Tree Manager script so that each one is held in a separate script so that I can pause and play them from the manager. I created a “pause” and “play” function that I can call
Hello,
I just tried your script here and Pausing the behaviour trees works fine. I mean they actually get paused apart from the icon showning them paused in the inspector.
To test it by the way, I just added this in your script:
1 2 3 4 5 6 7 |
void Update(){ if (Input.GetKeyDown(KeyCode.Space)){ PauseSecondaryTree(); } } |
Does doing the above not work for you?
Thanks.
(PS: Sorry for the code formatting bug. It’s now fixed)
Join us on Discord: https://discord.gg/97q2Rjh
That does work. 🙂
It seems like you can pause/unpause once, but after that first time it doesn’t work anymore…
Do you see that as well?
The way I did this is I put the BT manager in a parent object with a BTOwner. It had the following tree.
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
{ "version": 2.29999995231628, "type": "NodeCanvas.BehaviourTrees.BehaviourTree", "name": "Pause_Parent", "comments": "", "translation": { "x": -4637.30908203125, "y": -4928.890625 }, "zoomFactor": 0.964719712734222, "nodes": [ { "dynamic": false, "random": false, "_collapsed": false, "_position": { "x": 5490.0, "y": 5190.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.Sequencer", "$id": "2" }, { "policy": "FirstFailure", "dynamic": false, "_collapsed": false, "_position": { "x": 5490.0, "y": 5295.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.Parallel", "$id": "3" }, { "dynamic": false, "random": false, "_collapsed": false, "_position": { "x": 5400.0, "y": 5385.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.Sequencer", "$id": "4" }, { "_action": { "waitTime": { "_value": 3.0, "_name": null }, "finishStatus": "Success", "_isActive": true, "overrideAgent": null, "$type": "NodeCanvas.Tasks.Actions.Wait", "$id": "6" }, "_collapsed": false, "_position": { "x": 4995.0, "y": 5490.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.ActionNode", "$id": "5" }, { "_action": { "method": { "_returnInfo": "System.Void", "_baseInfo": "BTManager|PauseSecondaryTree", "_paramsInfo": "", "$id": "10" }, "parameters": [], "returnValue": { "_type": "System.Object", "_value": null, "_name": null, "$id": "12" }, "_isActive": true, "overrideAgent": null, "$type": "NodeCanvas.Tasks.Actions.ExecuteFunction_Multiplatform", "$id": "9" }, "_collapsed": false, "_position": { "x": 5115.0, "y": 5490.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.ActionNode", "$id": "8" }, { "_action": { "waitTime": { "_value": 3.0, "_name": null }, "finishStatus": "Success", "_isActive": true, "overrideAgent": null, "$type": "NodeCanvas.Tasks.Actions.Wait" }, "_collapsed": false, "_position": { "x": 5310.0, "y": 5490.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.ActionNode", "$id": "13" }, { "_action": { "method": { "_returnInfo": "System.Void", "_baseInfo": "BTManager|StartSecondaryTree", "_paramsInfo": "", "$id": "18" }, "parameters": [], "returnValue": { "_type": "System.Object", "_value": null, "_name": null, "$id": "20" }, "_isActive": true, "overrideAgent": null, "$type": "NodeCanvas.Tasks.Actions.ExecuteFunction_Multiplatform", "$id": "17" }, "_collapsed": false, "_position": { "x": 5460.0, "y": 5490.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.ActionNode", "$id": "16" }, { "_action": { "waitTime": { "_value": 3.0, "_name": null }, "finishStatus": "Success", "_isActive": true, "overrideAgent": null, "$type": "NodeCanvas.Tasks.Actions.Wait", "$id": "22" }, "_collapsed": false, "_position": { "x": 5640.0, "y": 5490.0 }, "_name": null, "_tag": null, "_comment": null, "_isBreakpoint": false, "$type": "NodeCanvas.BehaviourTrees.ActionNode", "$id": "21" } ], "connections": [ { "_infoExpanded": true, "_sourceNode": { "$ref": "2" }, "_targetNode": { "$ref": "3" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" }, { "_infoExpanded": true, "_sourceNode": { "$ref": "3" }, "_targetNode": { "$ref": "4" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" }, { "_infoExpanded": true, "_sourceNode": { "$ref": "4" }, "_targetNode": { "$ref": "5" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" }, { "_infoExpanded": true, "_sourceNode": { "$ref": "4" }, "_targetNode": { "$ref": "8" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" }, { "_infoExpanded": true, "_sourceNode": { "$ref": "4" }, "_targetNode": { "$ref": "13" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" }, { "_infoExpanded": true, "_sourceNode": { "$ref": "4" }, "_targetNode": { "$ref": "16" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" }, { "_infoExpanded": true, "_sourceNode": { "$ref": "4" }, "_targetNode": { "$ref": "21" }, "_isActive": true, "$type": "NodeCanvas.BehaviourTrees.BTConnection" } ], "primeNode": { "$ref": "2" }, "canvasGroups": [], "localBlackboard": { "_name": "Local Blackboard", "_variables": { }, "$type": "NodeCanvas.Framework.Internal.BlackboardSource" } } |
Then in a child object there was another BTOwner which only had a timer to test if it was being paused or not… I ran the parent on repeat.
It works the first time through, but the timer acts weird and doesn’t stop the second time the “pause” behavior is run.
Hey,
So, I did test exactly that and still it works. I have attached the test case here. Let me know if this works as expected for you. The BT get paused and unpaused correctly.
Join us on Discord: https://discord.gg/97q2Rjh
*Edit – Refreshed and found it!!
Hey to you,
I don’t see the attachment… I’m a lost soul. 😉
Could you point me in the right direction.
This is a better example of what I am trying to do. If you look at the child object, the pause stops working the 2nd time around…
Hm. The contents of your attachement is exactly the same as the one I’ve send, except that “BTManager_2” right?
So. Because it works fine here, I am going to suppose that it’s something fixed in the last version.
If you drop me an email at ‘support@paradoxnotion.com’ with an invoice ID, I will send you the last version asap which is exactly what Im using here and this example works fine.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
By the way, the new version is also already submited to the asset store and will be live at any moment 🙂
Join us on Discord: https://discord.gg/97q2Rjh
I created two behavior trees that should be linked to the gameobject. In your version there weren’t any BTs… Odd.
I will wait and try out the new version before bothering you again. 🙂
Thanks!