ConditionTask should have OnExecute, OnStop methods. I use event listener in a ConditionTask. I subscribe and unsubscribe to events. Is there any workaround for this? I can use a bool to catch the first update and subscribe event. There is no method for stop to unsubscribe.
If you are referring to ConditionTasks executed in the context of an FSM (transitions), then you can use the “OnEnable” and “OnDisable” overrides for this.
In the context of Behaviour Trees and because a ConditionTask, has no proper time in which it can be considered “enabled/disabled”, the overrides are not called, but I am thinking that for the shake of consistency, they should be when the Behaviour Tree starts and stops respectively.
onenable and ondisable can cause undesired behaviours. there should be a function that runs just before first checking the condition. and there should be an exit function that runs just after the success case. also, ondisable should call exit function if the condition is active. onenable and ondisable are related directly to the gameobject. you can activate gameobject before using condition. maybe you never use condition buy you can enable condition game object. similarly, you can disable game object lately or you can cache it. so there should be functions related condition.
OnEnable and OnDisable method in Condition tasks don’t share the same calling way of OnEnable and OnDisable of Monobehaviour if that is what you meant. In the context of FSM, OnEnable and OnDisable will be called pretty much when you describe:
– OnEnable, will be called once the parent state gets active and just before the first check.
– OnDisable, will be called once the parent state exits.
Please let me know if I misunderstood what you meant.
Thank you.
No, it is not what I want. currently; when I set transition condition to “check after state finished”, onenable on condition works immediately. I need a function that runs when the state finish and just before condition oncheck executes for the first time. I don’t want to subscribe to events early.
I generally run my tasks in sequence and I set transition condition to “check after state finished”.
Hmm. I see. I didn’t know you were using “Check After State Finish”.
I will look into changing the OnEnable in that case, so that it will be called after the state finished like you describe.
Will that change work for you?
for OnEnable, yes. will OnDisable execute before the first action of the next state? subscribe events will be at OnEnable and unsubscribe events will be at OnDisable.