What is Blackboard Key filtering used for?

I’m a newbie to AI in Unreal Engine and I have a question regarding Blackboard Keys filtering. So, to cut to the chase, what is it used for? For example we can write:

MyObjectKey.AddObjectFilter(this, GET_MEMBER_NAME_CHECKED(UMyBTTask, MyObjectKey), AActor::StaticClass());

and my first thought was that this instruction makes Unreal check if the class we pass to the Blackboard Key is of the right type, is it correct? Or here:

MyFloatKey.AddFloatFilter(this, GET_MEMBER_NAME_CHECKED(UMyBTTask, MyFloatKey));

Does it just check if the value we’re passing is a float?

I was digging a lot to find an answer, but found nothing, so I hope there will be someone to help me out, thanks in advance and have a nice day!

I’m not too experienced with this, but with the things I know you are correct. The AddObjectFilter and AddFloatFilter methods are used to filter the values that can be assigned to the blackboard keys.

When you create a blackboard key, you can specify the allowed value types for that key. For example, if you create a blackboard key with the allowed value type of AActor, then you can only set that key’s value to an instance of the AActor class or one of its subclasses.

However, sometimes you may want to further restrict the types of values that can be assigned to a blackboard key. This is where the filters come in.

For example, in the code snippet you provided, the AddObjectFilter method is used to filter the allowed types of objects that can be assigned to the MyObjectKey blackboard key. Specifically, it allows only instances of the AActor class or one of its subclasses.

Similarly, the AddFloatFilter method is used to filter the allowed types of floating point values that can be assigned to the MyFloatKey blackboard key. It allows only values of type float.

These filters can help ensure that the values assigned to blackboard keys are of the correct type and prevent errors from occurring.

2 Likes

Thanks so much for making it clear! However I do have some more questions, if I was trying to assign a variable of some other type to a blackboard key, wouldn’t it give me an error?

For example if I was trying to assign an FVector variable to a floating point blackboard key, the types don’t match, so it shouldn’t even compile… Or is it ignored when it comes to blackboard keys? I tried running those lines of code:

Blackboard->SetValueAsVector("TargetLocation", FVector::ZeroVector);
Blackboard->SetValueAsFloat("TargetLocation", 5.0f);

The first one works as intended, the types match, so it gets assigned, however, the second one just gets ignored, there’s no error and the value obviously doesn’t change, what would filters change in that case?

1 Like

In this case, since SetValueAsFloat is attempting to assign a float value to the TargetLocation Blackboard key, the value will be accepted and stored successfully. However, if you try to assign a value of a different type, such as a vector, the filter will prevent it from being set, and you should see an error in your console or log output indicating that the value could not be set due to a type mismatch.

It’s important to note that the filter is not designed to prevent invalid or unexpected values from being set on the Blackboard key. Its purpose is simply to ensure that the values being set are of the correct type. It’s up to you as the developer to ensure that the values being set on the Blackboard key are appropriate for your AI system and won’t cause unexpected behavior.

1 Like

That solves my problem, thank you for your time and the desire to help! Best wishes! :slight_smile:

1 Like