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
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespaceGame.Tasks.Conditions
{
[Name("On Variable Changed")]
[Category("✫ Blackboard")]
publicclassBBVariableChanged:ConditionTask
{
[BlackboardOnly]
publicBBParameter<object>BBVar;
protectedoverridestringinfo{
get{returnBBVar+" Changed.";}
}
protectedoverride stringOnInit(){
if(BBVar.isNone){
return"Blackboard Variable not set.";
}
returnnull;
}
protectedoverride voidOnEnable(){
BBVar.varRef.onValueChanged+=OnValueChanged;
}
protectedoverride voidOnDisable(){
BBVar.varRef.onValueChanged-=OnValueChanged;
}
protectedoverride boolOnCheck(){
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.