Document about Start Event / BehaviorAgent

Description of Start On Event Message is duplicated.

and about BehaviorAgent,
I don’t know if I missed it, but I couldn’t find a document about the BehaviorAgent.
How do I control Graph through Script?
Can I trigger “OnStart” Node directly through the script without using “Start On Event Message”?

I tried Start(Restart) using the BehaviorGraphAgent, but the results were different from what I expected.

It is different from the behavior that was initially performed through OnStart and the behavior that was restarted through Restart(Start) in Script.

I think it would be better to have a document about the BehaviorAgent or Script API

Hi Seoyeon,

Thank you for reporting the documentation issue. It also brought to our attention that this particular node documentation is still lacking a bit of documentation.

There is a bit of confusion caused by indirections from our or side, sorry for the inconvenience :bowing_man:

Let me try to clarify them:

BehaviorAgent class name is BehaviorGraphAgent

BehaviorAgent class is actually named BehaviorGraphAgent (several users has reported this issue and we are investigating how to best handle this situation). You can find the documentation for it here.


Start On Event Message node

  1. StartOnEventMessage is an event node used to listen and wait to an EventMessage (a special ScriptableObject) before starting. (I’ll let the team know about the need to provide a new documentation page to touch on that subject).
  2. At the moment, it is not possible to control BehaviorGraph manually from your own script. We would recommend to make use of the BehaviorGraphAgent (just as you did). We are currently looking into ways to adds more control over the lifecycle strategies of your BehaviorGraphAgent (more control over when graph should start, update and terminate).

In regards to your situation, if your goal is to control when your graph start, you could try one of these 2 options:

  1. Disable your Behavior(Graph)Agent component on your gameobject and handle it’s enabled property to init/start and pause the behavior.
  2. Make use of EventChannel
    1. In a BehaviorGraph blackboard, create a new EventChannel using the wizard: Events > create new event channel type...
    2. Once created you should have a new BlackboardVariable for it
    3. Create a Start On Event Message node and assign your subgraph (anything that should have been below the default On Start node).
    4. When non-assigned, EventChannel are local to each graph (runtime) instance. But it is also possible to create an asset to make them shared accross different graph and scripts.
      • From project tab, right-clight Create > Behavior > Event Channels > ...
    5. From a script, you can now either:
      1. Have a reference to your Behavior(Graph)Agent and retrieve the local instance of the event channel using the BlackboardReference.GetVariableValue API (MyAgent.BlackboardReference.GetVariableValue("BlackboardVariable_EventChannel_Name", out var out_eventChannel)).
      2. Or use an EventChannel asset reference and call SendEventMessage on it to propagate to all the graph listening.

Sorry for the wall of text, I hope this will help you achieve your goal.

EventChannel is a really powerful functionality but we haven’t had time to cover them much in details in the documentation or samples yet.

We have plans to provide a new demo that shows how to use Behavior and integrate it with other C# systems. We will keep you posted :slightly_smiling_face:

1 Like

Thank you for your quick and kind reply!

The information you gave me was helpful.
It’s good to know how to operate locally without creating an EventChannel asset
I agree that using EventChannel settings is powerful.
I think it’s similar to the event channel method using ScriptableObject. (Maybe the same)

However, in my case, there was a problem that the cost of management increased as SO asset began to increase.
As the size of the game grew, the number of event channel SOs almost increased to hundreds of thousands.
So I wanted a way to use Script or get called in a local way.
I think it works well.

But there are some unresolved issues.

Q1) so… is this not recommand way?


It seems to trigger well
Is there an unexpected problem with using it like this?

Q2) ReTrigger still results differently than intended
Here is the process I tried following the advice


Yes. It triggers well.
But the result is a little strange.

Results of the first try
1
2
3
4 // after 3 sec

Results of the second try
1
2
3
4
4
4 // after 3sec

why result is different??

I found out while testing.
Regardless of how the Start trigger works, if i re-enter, i have the same symptoms
The same thing happens when i use OnStart + Repeat.

Why is the result different from the second Repeat?

I think maybe…
From the second Repeat, “Wait For All” doesn’t seem to be working properly.

According to the document
“It can’t restart until the child’s subgraph has ended.”
Do I have to explicitly ended the subgraph?

But that’s strange to say.
Doesn’t Repeat happen because the graph is finished?

Hi Seoyeon, sorry for the delay.

I would recommend using bg.Restart to ensure the graph is properly restarted or using bg.enabled if your goal is to pause/resume the graph.
We are working on clarifying our API usage and Start should only be called once either after the BehaviorGraphAgent.Init, or after calling bg.End.

We shortly discussed it with the team last week and one potential issue is that you can run into a situation where you have a subgraph running and calling Start would simply start again the graph without terminating the running nodes. This could lead to undesired behaviors.

You might have found a bug here, we’ve finally have sorted out our bug backend, so I’ve filled the very first ticket with your bug - https://issuetracker.unity3d.com/product/unity/issues/guid/BEHAVB-1 (Might take a little while to be available).

On another note, could you tried the using the Restart mode of the StartOnEvent node (can be set by selecting the node and setting Mode in the Inspector) and let me know if that solve the issue?

In case you are working with a very big amount of entity, it is indeed going to become an issue. We are aware that we need to improves our usage of ScriptableObject to reduce memory footprint and instantiation performance.

Thank you for your patience!

1 Like

Thank you for your answer
The same problem still occurs with Restart mode.

image

The same problem occurs with OnStart + Repeat.
In any way, Wait For All re-entry does not work normally.

Can I ask you to check this issue additionally?

To sum up briefly
there seems to be no way to check the real-time value of SharedBlackboard in the UI such as the Inspector
It always only displays the initial value

1 Like