Variable Synchronizer

Shared Variables are great for sharing data across tasks and behavior trees. However, in some cases you want to share to same variables with non-behavior tree components. As an example, you may have a GUI Controller component which manages the GUI. This GUI Controller displays a GUI element indicating whether or not the agent being controlled by the behavior tree is alive. It does this by having a boolean which says whether or not the agent is alive:

public bool isAlive { get; set; }

With the Variable Synchronizer component, you can automatically keep this boolean and the corresponding Shared Variable synchronized with each other.

To setup the Variable Synchronizer, first make sure you have created the Shared Variables that you want to synchronize. For this example we created three Shared Variables:

Following that, add the Behavior Designer/Variable Synchronizer component to a GameObject.

Next, start adding the Shared Variable that you want to keep synchronized. For this example we are going to add the Is Alive variable that was previously mentioned.

  1. Specify the GameObject which contains the behavior tree that has the Shared Variable that you want to synchronize.
  2. Select from the popup box which Shared Variable you want to use.
  3. Specify a direction. If the arrow is pointing to the left then you are setting the Shared Variable value. If the arrow is pointing to the right then you are getting the Shared Variable value.
  4. Specify the type of synchronization. Currently the following types are supported: Behavior Designer, Property, Animator, and PlayMaker.
  5. The remaining steps will depend on the type of synchronization selected. In this example Property was selected so you’ll need to select the component which contains the property that you want to synchronize with the Shared Variable.
  6. Click Add.

Once added the Is Alive Shared Variable will set the isAlive property at an interval specified by Update interval. The following screenshot contains a few more synchronized variables:

  • The Is Alive Shared Variable is setting the isAlive property.
  • The Speed Share Variable is setting the Speed Animator parameter.
  • The Target Shared Variable is being set by the Target PlayMaker variable.