When working with Events in Behavior I encountered some issues:
- The preview of the node is missing some spaces when writing out the story.
- The New Event Channel story modal does not detect blackboard variables like the rest of the custom node creation. In this example I would have expected “Self” and “TargetLocation” to be identified as GameObject and Vector3 respectively.
- When generating an event with a custom type like in this example, the generated event class has compilation errors because it does not add the “using” statements to know about that class.
None here are insurmountable issues, but resolving them would be a better experience using the tool.
Cheers!
Chris
1 Like
Thank you for your post Chris - big fan here :D!,
if you have multiple instances of an agent using the same behavior graph - E.g. OnHealthChanged-Events will get called on all Agent Instances. From what I have tried, it is not possible to modify a custom event channel (since this modification need to be done in the WaitFor Node) to only listens to events thrown by the same agent (So e.g. my Agent GO has a Health Component, which sends the event - the Reciever is the “Wait For” node. Since the event channel doesnt know anything about where its being used, we can not >only register to events thrown from the same gameobject<. My workaround was to create an instance of the event channel and set the variable in the behavior graph, but this is tied to a string value…:
if(behaviorAgent == null) {
Debug.LogError("Behavior Agent is not set in the inspector");
return;
}
_energyValueChangedInstance = ScriptableObject.CreateInstance<EnergyValueChanged>();
if (!behaviorAgent.BlackboardReference.SetVariableValue(GetBlackboardVariableName(), _energyValueChangedInstance)) {
Debug.LogError($"Blackboard variable: {GetBlackboardVariableName()} could not be set, the variable name is incorrect or the variable does not exist in the blackboard");
}
protected override string GetBlackboardVariableName() {
return "OnHungerChangedEvent";
}
I feel like having the option in the “WaitFor” - Node to only listen to Thrown Events by [GameObject] would be a gamechanger.
1 Like
Hi @ChrisKurhan, thanks a lot for all the feedback!
I can confirm that I’ve been able to reproduce the issues 1 & 2 you’ve mentioned, I’ll report these as bugs and will try to get them fixed as soon as possible. No promises yet but I’m hoping that we’ll get them resolved and in already for the next update.
For issue 3, is the GatherableSupply
custom type that you have created not a MonoBehaviour or part of the UnityEngine namespace? If it’s okay, it would be great to get more details on the variable type and how to reproduce the compilation errors.
Hi Laura!
I have defined GatherableSupply
as a MonoBehaviour
.
namespace GameDevTV.RTS.Environment
{
public class GatherableSupply : MonoBehaviour, IGatherable
…implementation stuff
}
}
I have a default project namespace, let’s say LlamAcademy.RTS
. My GatherableSupply
is in LlamAcademy.RTS.Environment
When I create the Event, the class is created in the global namespace (disregards project default namespace and any folder structure) and does not add any using LlamAcademy.RTS.Environment;
to know about the GatherableSupply
.
I hope that’s enough info to reproduce. I can get it to happen every time.
1 Like
@ChrisKurhan Ah that’s right, thanks a lot for the clarification. I could get a repro now and can indeed confirm that this is an existing issue. The script generation is still quite basic but we’ll definitely want to avoid any compilation errors and improve it so that it takes namespaces into account.
I’ll log a bug ticket for this, and either me or someone else from the team can take a look at it soon.
Thanks again!
1 Like
The new Unity Behavior Graph Demo answers this question.
If the Blackboard Variable Field is left empty from the Event Channel, it creates a new Instance of that Event Channel. We can simply access ist via:
if (!m_StateMachine.BlackboardReference.GetVariableValue(k_StateChannelVariableName, out m_StateChannel))
{
Debug.LogError($"{m_StateMachine} is expecting a BlackboardVariable of type '{typeof(CharacterStateEventChannel).Name}' named " +
$"{k_StateChannelVariableName}.");
return;
}
m_StateChannel.name = this.transform.parent.name + " State Channel";
Renaming the Channel is optional.