UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

architecture

[UVS] Sharing EventChannel Assets for Inter-Graph Communication

Solution

project architectureeventsoptimizationscripting

Unity 2021.3.x - Unity 6.3.x

Published 13 days ago

Issue

 Communication between distinct Visual Scripting graphs, such as parent and child agents, often requires complex component-based mediators. Establishing these links is difficult when agents are dynamically spawned, as standard Blackboard variables are often perceived as being unique to the graph instance.

Explanation

The BlackboardVariable instances that reference EventChannel assets do not create unique copies for each graph. They maintain a reference to the same global asset, allowing for decoupled event-driven communication.

  1. Create an EventChannel ScriptableObject class in your project.
  2. Right-click in the Project window to create an EventChannel asset.
  3. Open the Blackboard of the target graphs (e.g., your parent and your child graph).
  4. Define a new variable in both graphs and assign your EventChannel asset to the value field.
  5. Use your graph to trigger an event on the EventChannel.
  6. Use the listening graph to react to the event via the same EventChannel.

The Shared property in the Blackboard determines variable visibility across instances of a ScriptableGraph, but because the EventChannel is an external asset, the underlying reference is shared regardless of this toggle.

Additional Tips:

  • Ensure your EventChannel class uses [CreateAssetMenu] for easy asset instantiation.
  • Use EventChannel for one-to-many communication where multiple disparate systems need to respond to a single trigger.
  • Avoid using DontDestroyOnLoad on your EventChannel asset directly; instead, ensure the references are managed within your scene lifecycle.

TL;DR

EventChannel ScriptableObject references assigned to BlackboardVariable instances are inherently shared across graphs, removing the need for mediator components or manual referencing.


Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.