Issue with BlackboardVariable.ObjectVariable Null Comparison in Behavior Package 1.0.2

I’ve encountered a strange issue when working with the Behavior package version 1.0.2. Specifically, I’m trying to check whether a BlackboardVariable.ObjectVariable is null. However, a direct comparison to null returns false, which is unexpected.

For context, when I run:

Debug.Log(BlackboardVariable.ObjectValue);

It logs null as expected, but if I try:

if (BlackboardVariable.ObjectValue == null)
{
    // Never enters this block
}

The comparison fails. After some trial and error, I found that the only way I can reliably check for null is by doing the following:


if (BlackboardVariable.ObjectValue.ToString() == "null")
{
    // This works
}

For context, I was trying to write simple null checking condition:

public partial class IsNullCondition : Condition
{
    [SerializeReference] 
    public BlackboardVariable Variable;

    public override bool IsTrue()
    {
        return Variable.ObjectValue == null;
    }
}

This feels like an odd workaround, and I’m not sure why the direct comparison doesn’t behave as expected. Has anyone encountered a similar issue, or does anyone have insights into why this is happening? Any suggestions for a cleaner approach would be greatly appreciated.

1 Like

I had the same problem. I took a look at some internal actions implementations and they suddenly started using ReferenceEquals(Agent?.Value, null) for these checks.

I’ve rewritten my code do to so and it never bothered me again.

Yes it’s working and it’s definitely better solution than mine, but it’s still a bit counter intuitive to check for null this way.

1 Like