NodeCanvas Forums › General Discussion › Condition Question
I have a custom condition that listens drag event of InputTouches asset. i subscribe this condition to InputTouches event. i want this condition to listen only it is candidate to run like it is connected to the active state. OnInit runs when it will be used for the first time. is there any other method that runs once and just before OnCheck?
with this code i can subscribe and unsubscribe. if there are 2 conditions on a state. i miss one subscription. i need a function like ActivatingCondition, DeActivatingCondition.
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 |
public class OnDraggingCondition : ConditionTask { private bool _listens; public int Index; private bool _started; protected override string info { get { var finalString = "OnDraggingCondition"; return finalString; } } /*protected override string OnInit() { _started = false; IT_Gesture.onDraggingE += ItGestureOnOnDraggingE; return null; }*/ private void ItGestureOnOnDraggingE(DragInfo dragInfo) { Debug.Log("OnDraggingCondition Index:" + dragInfo.index); if (dragInfo.index == Index) { IT_Gesture.onDraggingE -= ItGestureOnOnDraggingE; _started = true; } } protected override bool OnCheck() { if (!_listens) { IT_Gesture.onDraggingE += ItGestureOnOnDraggingE; _listens = true; } if (_started) { _started = false; _listens = false; return true; } return false; } } |
Hey,
Yeah. Such a method is missing. It’s a nice request. I will add in the next version.
I can walk you through into quickly and temporary adding this now if you want, but chances are that the implementation will change.
Let me know if you want.
Cheers
Join us on Discord: https://discord.gg/97q2Rjh
it would be nice to add such feature. it will useful for resource consuming processes.
i could not understand about what you ask about what i want? sorry for my English 🙂
Hey,
Sure I will add this. It would be very usefull in the case of conditions.
I simply asked you if you want to tell you how to change the source code to make this, instead of waiting for the update to come in the asset store 🙂
Join us on Discord: https://discord.gg/97q2Rjh
yes i would like to know it now 🙂
Sure. So here what you need to do in the source code:
1) Open up ConditionTask.cs and add this code:
1 2 3 4 5 6 7 8 9 10 11 12 |
public void Enable(){ OnEnable(); } public void Disable(){ OnDisable(); } virtual protected void OnEnable(){} virtual protected void OnDisable(){} |
2) Open up FSMState.cs and add this code in line #104 just before the OnEnter(); call:
1 2 3 4 5 6 |
for (int i = 0; i < outConnections.Count; i++){ if ( ((FSMConnection)outConnections<em class="d4pbbc-italic"></em>).condition != null) ((FSMConnection)outConnections<em class="d4pbbc-italic"></em>).condition.Enable(); } |
3) Also in FSMState.cs add this code in line #158 just before the OnExit(); call:
1 2 3 4 5 6 |
for (int i = 0; i < outConnections.Count; i++){ if ( ((FSMConnection)outConnections<em class="d4pbbc-italic"></em>).condition != null) ((FSMConnection)outConnections<em class="d4pbbc-italic"></em>).condition.Disable(); } |
So now you can override OnEnable and OnDisable in your condition tasks to handle what you are after 🙂
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
thanks 🙂 will you also add this to the next release?
Hey,
Sorry for late reply.
Yes this will exist in the next release 🙂
Join us on Discord: https://discord.gg/97q2Rjh
At OnEnable Method i cannot get Blackboard values. when i debug at OnEnable i can see there are variables at GlobalBlackboard. but result belove is null. it cannot evaluate $Global/MyReference at OnEnable.
1 2 3 4 5 6 |
public BBParameter<GameObject> Root; protected override void OnEnable() { root = Root.value; } |
Hey,
Really sorry for the late reply. I missed it somehow.
I just tried this out and it really works as expected. The variable value resolves correctly from the GlobalBlackboard. What is your setup?
Could you please send me a reproduction project to check this out?
Thanks
Join us on Discord: https://discord.gg/97q2Rjh
i will check it with bounded FSM. have you tried it with FSM as Asset?
Hey,
Please check your other post where I think it answers for this post as well 🙂
Let me know.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh