FSM SuperActionState OnUpdate callback triggered only once

NodeCanvas Forums Support FSM SuperActionState OnUpdate callback triggered only once

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10868
    aelkhan
    Participant

    Hello,
    Sorry if this question has already an answer, I could not find it in the documentation neither by a forum search.
    Maybe I misunderstood but I thought that the “OnUpdate” callback of a SuperActionState was invoked continuously (on each frame maybe ?). I made some tests and this callback is called only once (in the same frame as the “OnEnter” callback actually). Please see screenshots (not visible on screenshot but my blackboard variable startTime is bound to the field TestFsm.startTime).
    Is this behaviour the expected one or did I miss anything ?
    If it is expected, what is the best way to perform an action continuously when in a specific state ? Using the OnStateUpdate(IState state) callback (and checking the state is the good one) ?
    Thanks in advance for your replies

    Attachments:
    You must be logged in to view attached files.
    #10871
    Gavalakis
    Keymaster

    Hello,

    Thanks for the detailed explanation.
    The way the the SuperActionState works, at least right now, is that it will keep updating for as long as an action in the OnExecute list is updating. Like the node help states ‘The state is Finished as soon as the longest action in the OnEnter list is Finished’. This is done by design since otherwise there would be no other good way to determine when to Finish the state.

    So, there are various ways to tackle this.

    1. If you add a RunForever action in the OnEnter list, it will work as you expect, but of course the state will never Finish by itself, so any OnFinish transitions will never happen.

    2. If getting a callback is what you are after, then it’s probably best (or at least easier) if you use a normal ActionState and check the “Repeat State Actions” (even if there are no actions) and implement the OnStateEnter, OnStateUpdate and OnStateExit in your MonoBehaviours. Doing this will have the same effect as adding a RunForever. It will simply make the state never Finish and always Update up until a transition is made due to some condition.

    Let me know if this works for you and of course I’d be glad to hear any suggestions.
    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    #10878
    aelkhan
    Participant

    Thank you very much for your answer.
    The proposal #2 will be fine but raises a question : if I implement a “OnStateUpdate” in several scripts (let’s say script1 and script2) attached to the GameObject owner of my FSM, is there a way to control (or to know) the execution order of script1.OnStateUpdate and script2.OnStateUpdate ?
    Thanks in advance

    #10880
    Gavalakis
    Keymaster

    Hello again,
    The order they will be called are the order of the components on the gameobject, top to bottom. 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

    #10883
    aelkhan
    Participant

    Quick and precise 😉
    Thank you sir.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.