Maintaining state with actions

NodeCanvas Forums General Discussion Maintaining state with actions

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9238

    Just wondering what is the best way to handle this.

    So lets say I have an action which encapsulates spawning objects, now I want to maintain state between calls so I can remember how many objects have been spawned, so are actions instantiated per invocation or are they kept around for the lifetime of the tree?

    #9241
    Gavalakis
    Keymaster

    Hey,

    All nodes and tasks are instantiated for lifetime, so you can definetely store the number of times between executions.

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

    #9240

    Hey,

    So on the flip side of this, is there a best way to reset the state of an action?

    I can always just reset stuff before or within the EndAction() method, but was not sure if there was some preferred way to do so, as I am not sure if OnInit is called first time the action is created or every time the action is re-used after its ended.

    #9239
    Gavalakis
    Keymaster

    Hey,

    OnInit is called just once before first execution, so it’s not a good candicate. It’s best to use OnStop since that’s called whenever you call EndAction or the Action ends due to any other reason, like being interrupted for example.
    Or you can reset some variables within OnExecute which is called once on EACH execution. Depending on what you are after.

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

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