Accessing Blackboard from C#

Using Behavior 1.0.7

I have a simple blackboard with only one shared variable in it of type List. I copied the GUID and I want to set the value from C#.

(BTW, the documentation page https://docs.unity3d.com/Packages/com.unity.behavior@1.0/manual/bind-c#.md is broken, because of the #, but one can find that page in the package…)

I have a public variable of the BehaviorGraphAgent, it is set. This code works:

  [SerializeField] public BehaviorGraphAgent m_Agent;
    public void sample()
    {
        
        SerializableGUID guid = new SerializableGUID(1, 0);
        BlackboardVariable<GameObject> aBbv;
        m_Agent.BlackboardReference.GetVariable(guid,out aBbv);

However, if I use the GUID of the variable in a shared blackboard, the code fails.
How are we supposed to access them?

Hello @Captain720
Sorry for the late reply, the team is slowly coming back from holidays.

Just to clarify, are you trying to access a BlackboardVariable from a BlackboardAsset that is linked to a BehaviorGraph? If so, you need to use BehaviorGraphAgent.GetVariable instead of using BlackboardReference.GetVariable.
This is because BehaviorGraphAgent.BlackboardReference is refering to the BG-specific blackboard. Using the GetVariable from the Agent will looks for BBV from any blackboard referenced by the agent’s graph instance.

Also thank you for reporting the documentation page link issue. A fix will land with the next package release. In the meantime, you can find an early draft of it on this thread: Behaviour Graph Events to GameObjects without Behaviour Graphs - #2 by MorganHoarauUnity

Hope this helps :slightly_smiling_face: