Running an FSM "instantly"

NodeCanvas Forums General Discussion Running an FSM "instantly"

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #8730

    Hey!

    I’d like to use NC to visually lay out a node graph for generating a sequence of events for our game. Thing is, I want to run this FSM instantly, until it terminates, and just queue up the events in a list.

    Here’s a mockup of the type of structure I would like to create. Each “Action” will be a custom ActionTask that adds some element (an event, or “day” preset) to a list. Something like:

    FSM for sequence of days

    Is there any way to trick NC into running through the FSM all at once, without waiting for updates? Basically I just want to use NC as a visual editor for an abstract graph :).

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

    Hey,

    What you are after is possible already considering I understood corectly.

    You can set the FSMOwner’s option on the inspector to “Do Nothing” OnEnable.
    Then at any given moment you start the FSM using:
    FSMOwner.StartBehaviour(); (or any overload of that).

    The FSM will start, traverse the transitions based on the conditions and as soon as it reaches a finished node without any outgoing transitions the FSM will automaticaly stop.

    Is that what you are after, or something you tried but it’s not what you are after?

    Let me know.
    Cheers!

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

    #8737

    The FSM will start, traverse the transitions based on the conditions and as soon as it reaches a finished node without any outgoing transitions the FSM will automaticaly stop.

    Will it traverse the whole FSM in a single frame? I was looking through the code but I got the impression that NC performs at maximum a single transition per frame..

    I guess I should just try it, haha! Apologies for being lazy. I’ll get back about this!

    #8735

    Ok. I did some testing, and it is how I thought.

    With a simple ActionTask:

    And the state machine of the previous screenshot. I get the following:

    Log showing consecutive frames

    Showing that the Nodes are executed in consecutive frames. The downside of this is that I’d need to work around _not_ having the timeline ready in the first frame. But I suppose I could just generate the timeline “on demand” as well.

    P.S. though oddly, the first two states are executed in frame 1?

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

    Hey!

    Sorry for the late reply. I was mostly away in weekend.
    Yes. They are not executed in one frame. I didn’t realize this is what you were asking :). It will required a lot of tweeks to make that happen, but I don’t think that would be an issue for what you are after.

    One thing that might help you, would be to start the FSM with the overload that takes a System.Action parameter, so that you get a callback when the FSM is finished after x frames and then use your timeline created in the FSM, which will be “ready” when the callback is called.

    Let me know if that helps.
    Cheers!

    (PS: Regarding first 2 states execution, it seems weird to be on the same frame. I will take a look at this)

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

    #8733

    I think it would be good to have FSM evaluate instantly instead of ticking through, I think it is more expected behaviour. One could always do a new FSM state that does ticking, but it is not possible to get rid of ticking with new custom FSM state :/ Or is it?

    #8732
    Gavalakis
    Keymaster

    Hello,

    I strongly believe that FSM states should be ticked per frame, considering that the FSM is indeed used as different States of a character/object rather than States representing actions one after another in a visual scripting fashion 🙂

    Also ticking the whole FSM in one frame, can very easily cause recursion problems, since the transitions can lead to an already executed state. Of course this can be checked and avoided but then the behaviour of the FSM will not be consistent and probably would be a pain to debug later on.

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

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