Best Practice for Runtime Instantiation

NodeCanvas Forums General Discussion Best Practice for Runtime Instantiation

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9160

    Hey I have a question regarding runtime instantiation. I will have objects being spawned randomly which will need a behaviour tree attached to them. Along with this, i believe they should have their own blackboard attached.

    Im following the example in the soldier scene provided with the Common blackboard and Common behaviour tree, then assigning them when the gameobject is created. However this means all objects instantiated share the same blackboard (from what i can tell). Now this blackboard contains very specific things to the gameobject, e.g. health or stamina. This causes all the spawned instances to behave the same, when they should all be unique.

    I would like to avoid attaching it directly to the prefab (in the editor), as i may have other types of objects to spawn which should use the same behaviour trees and it seems like a lot of maintenance to keep updating them.

    Any ideas or direction on how to approach this using NodeCanvas would be much appreciated.

    Thanks!

    #9161
    Gavalakis
    Keymaster

    Hello,

    Sorry for the late reply. I was on a trip out of office.

    Yes, using the same Blackboard in more than one BehaviourTreeOwners means that all blackboard’s variables will be common. If you don’t want to do this then each BehaviourTreeOwner will need to have it’s own Blackboard.

    Since the Blackboard is different than the BehaviourTree, why don’t you want to attach a BehaviourTreeOwner and a Blackboard component on all prefabs and assign the same BehaviourTree on all prefabs?

    Another way, would be to add the blackboard at runtime on the instantiated gameobject through normal AddComponent(), initialize it’s variables through code by using blackboard.AddData(Type) and set it to the BehaviourTreeOwner .blackboard.
    But I think it’s more managable to do it through the editor in the case that you do use prefabs.

    Generaly speaking you can do prety much everything at runtime as well.

    Here is some code too:
    http://nodecanvas.com/documentation/runtime-instantiation-and-tips/

    Let me know 🙂

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

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