Storing actions to be used later and BB variables

NodeCanvas Forums Support Storing actions to be used later and BB variables

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #16083
    mmalone
    Participant

    Hello,

    I’ve run into a scenario that I have not been able to work out.

    My combat system has 2 phases per turn.  1st phase is planning (player/AI).  Decided upon actions are put in a list (List<ActionTask>).  2nd phase executes the stored actions.

    The issue I’m running into is with blackboard variables.  Some of the stored actions use variables as you would expect.  Problem comes in when that action is stored (determined by the tree) more than once.  It appears the same action object is stored each time.  Even if that were not the case they all would share the same variable (correct?).   The last one wins (as expected I believe).  What I would like to happen (logically) is for the variable to get resolved (and new action instance?) when put into the list.

    Question:   Is there a way I can accomplish what I’m trying to do?  It’s fine if code is involved.  I would not be surprised if I went down the wrong path to begin with.

    NodeCanvas: Version: 3.2.1

    Unity: 2021.2.8f1

    Thank you,

    Mike

    #16088
    Gavalakis
    Keymaster

    Hello there,

    Can you please clarify what you mean by saying “stored” so that I can understand the rest of the context?

    Thank you!

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

    #16101
    mmalone
    Participant

    I have a BB variable (“PlannedActions”) of type List<ActionTask>.  The tree determines which action should go into that list to be run later.  In the image below “Add Action To List” is just my version of adding an element to a list.  In the image below I’m adding “Attack” to “PlannedActions”.

    AddTaskToList

    Sometime later I run the “Attack” action via a helper class.

    Make sense?

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

    Hello,

    This is a bit of an edge case and I am still a bit confused on the overall setup and what is meant to be achieved. I am really sorry :-/

    Are you adding the actions in the list by code?

    Could you please send me a small reproduction project so that I can see the whole thing and setup? (support_AT_paradoxnotion.com)

    Thank you!

     

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

    #16118
    mmalone
    Participant

    “support_AT_paradoxnotion.com” isn’t a valid email address or website.  I’ve attached the project.
    The behavior tree has a node (on the right) to add an action to a list and a node (on the left) to run the action.
    I had to create a script (RunAction.cs)) to do the work because I couldn’t figure out how to do it directly in nodecanvas.
    I removed the “ParadoxNotion” folder to make the zip file smaller.
    If there is a better way to delay the running of an action let me know.

    Thank you,

    Mike Malone

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

    Hello again,

    Actions are classes and as all classes in c#, they are passed by reference. That means that if you keep adding the same instance of a class in a list, all actions in that list will point/reference to the same original action instance (not a copy). This is just standard in C# (and most OOP languages).

    With that said, I think the way you try to accomplish your goal is a bit complicated and I would advice against adding ActionTasks in the graph dynamically this way.

    Can you please describe your END GOAL and what you are trying to accomplish, so that I can advice with an alternative solution?

    Thank you!

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

    #16125
    mmalone
    Participant

    I know what references are and I know C# very well.  That being said, looking over my previous questions I can see how you would think otherwise.

    Let’s try this.  What I’m trying to do may boil down to:  Is it possible to assign the VALUE of a BB variable to either another BB variable (so a copy) or non-BB variable (node has a C# variable declaration – “public float myfloat;”)?

    Ignoring my original question (the way I asked it).  How can I do the following:

    • A combatant plans out what it wants to do on the beginning of its turn and stores the resulting “action” (like shoot laser pistol at target).  There could be multiple actions (a “list” perhaps).  I’m not specifying how the action is stored (it’s part of my question).
    • Later, that same combatant goes through all the actions, one at a time, and runs them.

    How can I do this in the “NodeCanvas” way?

    Here are a couple thoughts I had:

    • There may not even be a “list”, perhaps a different path down the BT to run the action (trying not have duplication in the tree).  I suspect a subgraph would be involved.
    • Store the data required to run the action.  a script would access the BB to get the values.
    • Use an enum for each action type (if the number of types isn’t too large).  would still need to store data.

     

    #16140
    Gavalakis
    Keymaster

    Hello again,

    Hmm. So from the sounds of it, you would basically like some sort of a Sequencer, but with the ability to run its children nodes in a specific order rather than a predetermined one. Is that correct?

    Would something like a node where all its children have a weight (possible to set by a variable) and have all those children run in order of weight (high to low) work for you? This way you would be able to set the “weight” variables at the start of the tree (when you determine the order of actions basically) and then have that new node execute all its children in that order of weights.

    Please let me know.
    Thanks!

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

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