I’m trying to create a condition task that returns true when a BB variable changes. Everything works except OnDisabled gets called after the transition in a FSM. So in this case where should I unsubscribe from the OnValueChanged event to clean up the event listener?
I have modified your code to work as I expect you want it to:
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
usingNodeCanvas.Framework;
usingParadoxNotion.Design;
usingUnityEngine;
namespaceGame.Tasks.Conditions
{
[Name("On Variable Changed")]
[Category("✫ Blackboard")]
publicclassBBVariableChanged:ConditionTask
{
[BlackboardOnly]
publicBBParameter<object>BBVar;
protectedoverridestringinfo{
get{returnBBVar+" Changed.";}
}
protectedoverridestringOnInit(){
if(BBVar.isNone){
return"Blackboard Variable not set.";
}
returnnull;
}
protectedoverridevoidOnEnable(){
BBVar.varRef.onValueChanged+=OnValueChanged;
}
protectedoverridevoidOnDisable(){
BBVar.varRef.onValueChanged-=OnValueChanged;
}
protectedoverrideboolOnCheck(){
returnfalse;
}
privatevoidOnValueChanged(stringarg1,objectarg2){
YieldReturn(true);
}
}
}
Some notes:
– Use OnInit only for initialization similar to Unity’s Awake.
– Use OnEnable and OnDisable to subscribe and unsubscribe.
– You don’t have to call base implementation of methods.
– A BBParameter will never be null. Use .isNone to determine if the front-end user has selected a variable or not.
Thanks that works now for normal conditions but I did notice one issue. When the condition is part of a Concurrent node OnEnable is not called but OnInit is. Thus the condition does not work in Concurrent nodes because the event never gets setup.
Hello and sorry for the late reply.
You are correct. This is actually a bug in the Concurrent Node.
To fix this, please open up ConcurrentState.cs file and:
1) In the OnEnter Method, add this line of code above everything else: conditionList.Enable(graphAgent, graphBlackboard);
2) In the OnExit method, add this line of code first as well: conditionList.Disable();
Thanks for the report!
Join us on Discord: https://discord.gg/97q2Rjh
Author
Posts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.