Proper way to copy blackboard from unbound BehaviourTree to BehaviourTreeOwner?

NodeCanvas Forums Support Proper way to copy blackboard from unbound BehaviourTree to BehaviourTreeOwner?

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15157
    buddyhunter1
    Participant

    Hey, in my project I have a BehaviourTreeOwner component that I need to dynamically load various unbound BehaviourTree assets into during runtime. As part of this, I need to copy over the blackboard from the asset into the BehaviourTreeOwner so the variables in it can be accessed during runtime. I’ve tried this a couple ways and neither seems to work:

    (song is an instance of a class containing a BehaviourTree reference)

    _behaviorTreeOwner.behaviour = song.BehaviourTree;
    _behaviorTreeOwner.blackboard = song.BehaviourTree.blackboard;
    _behaviorTreeOwner.StartBehaviour();

    This throws this error when the middle line is reached:

    InvalidCastException: Specified cast is not valid.
    NodeCanvas.Framework.GraphOwner`1[T].set_blackboard (NodeCanvas.Framework.IBlackboard value) (at Assets/External/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/GraphOwner.cs:572)

     

    I have also tried getting the blackboard attached to the BehaviourTreeOwner’s game object as a component and then doing this:

    _blackboard.OverwriteFrom(song.BehaviourTree.blackboard);

    But this resulted in no variables in it getting updated during runtime even when the stock SetBoolean action was reached (and completing successfully).

     

    What’s the proper way I should be handling this?

    #15158
    buddyhunter1
    Participant

    Forgot to mention I’m using NodeCanvas v3.0.9  and Unity 2019.3.0f6

    #15160
    Gavalakis
    Keymaster

    Hello there,

    Hmm. May I ask why do you need to copy the Graph Blackboard variables into the GraphOwner Blackboard Component?
    When you load an Asset Graph into a GraphOwner (for example via owner.StartBehaviour(newGraph)), an instance of the graph is created and you can access the variables of the graph directly without the need to copy those variables into the Blackboard component attached along the GraphOwner. You can access those variables (the loaded graph’s blackboard variables) through owner.behaviour.blackboard. Since an instance of the graph is created when loading and starting an asset graph on a GraphOwner, modifying those variables will of course only modify the instance variables (and not the asset).

    Can you please clarify? 🙂
    Thanks!

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

    #15164
    buddyhunter1
    Participant

    Ah, didn’t realize that was done automatically. I was going off of the documentation here that suggests (to me, anyways) you need to do it manually: https://nodecanvas.paradoxnotion.com/documentation/?section=runtime-instantiation-tips

    Thanks!

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