Learn how to use NodeCanvas

The GraphOwner Component

The GraphOwner components are responsible for making an object behave based on a Behaviour Tree or an FSM, by either using the BehaviourTreeOwner, or the FSMOwner derived components respectively. These components do not contain the graph itself, but they are rather assigned a graph, unless the graph is bound.

  • To make a gameobject behave with a Behaviour Tree, you have to attach the BehaviourTreeOwner component to that gameobject.
  • To make a gameobject behave with an FSM, you have to attach the FSMOwner component.
  • You can attach both types if you want and any number of those on the same game object.

Once you have attached your GraphOwner component, you will need to assign it an actual graph. An assigned graph to an owner can either be Bound or an Asset.

  • A Bound Graph is local to the owner and is saved along with the gameobject. As such it is possible to have scene object references assigned within the graph if the owner is also within the scene.
  • An Asset Graph is a reference to a .asset file saved in your assets folder. The benefit of this is that such a graph can be assigned to any number of different owners, but the downside is that you can’t have scene object references assigned within it (this is a typical Unity restriction).

You always have the option to Bind an Asset graph, or to Save a Bound graph as an Asset file at any time through the editor GUI, so you don’t have to worry about this too much from the start.

All GraphOwner components have some common options for you to set in the inspector:

  • Blackboard: The Blackboard reference that is used (this is generally speaking set automatically)
  • First Activation: An option to define when the first graph activation will take place (OnEnable, OnStart, or Async). Async mode will load the graph in a separate thread and thus keep the main thread without any overhead. The only downside to that, is that the graph will be “ready” a few frames later (2-3). If that is problematic for your setup, consider using the OnEnable or the OnStart option. The default is OnEnable.
  • On Enable: Defines what will happen when the component is enabled (Enable Behaviour, or Do Nothing).
  • On Disable: Defines what will happen when the component is disabled (Disable Behaviour, Pause Behaviour, or Do Nothing).
  • Update Mode: When will the graph be updated (Normal, Late, Fixed Update, or Manual).
  • Pre Initialize Sub Graphs: If enabled, will pre-initialize all subgraphs as soon as the root graph is initialized (in GraphOwner Awake).

Finally, whenever you attach a GraphOwner component, a Blackboard component is also attached automatically if there is none attached already. The Blackboard is used to store variables that can be used within any of the graphs attached on the same gameobject, but more on Blackboards and variables can be read in Using the Blackboard section later on. Only one Blackboard is suggested to be used per game object.

Yes No Suggest edit
47 of 47 users found this section helpful
Suggest Edit