Blackboard Key Selector GetSelectedKeyID not working

Hi,

I have a blackboard key selector however when I attempt to get the blackboard key and cast it to the correct format it fails because the Key ID is wrong. All of the other information is correct which has meant that my current solution is to use SelectedKeyName instead which achieves the same result.

I just wanted to make you aware that this was an issue. The only blackboard key selector which appears to use GetSelectedKeyID correctly is the built in BlackboardKey.

Oh this is being done in C++ by the way.

Thanks,

Hey BurningArrowLtd-

Can you provide the code that you’re using or a sample project that demonstrates the issue you’re having. What type are you trying to cast the blackboard key to? Can you add any debugging lines to print the value you’re getting for the blackboard key before making the cast with it?

Hi BurningArrowLtd,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

Hi ,

I am having the same issue as the user above. I have a pretty simple behavior tree:

The services are implemented in c++, and in them I’ve been using the FBlackboardSelector so that I can set teh blackboard key in the behavior tree in the editor. The code I used looks like this:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = BlackboardKeys)
struct FBlackboardKeySelector TargetPosition_Key;

Like the previous poster, I found that when I used GetSelectedKeyID() to access the blackboard value in c++ I would get a debug value back, because the ID that is being returns is 255. I got around this by using the Key name instead:

OwnerComp.GetBlackboardComponent()->SetValueAsVector(TargetPosition_Key.SelectedKeyName, GoalLocation);

That line works as expected and sets the value as expected. The name also works for getting the value from the blackboard.

My problem comes from the BTTask_MoveTo task. It uses the ID like so:

const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());

I assume the ID must be failing here as well because it returns a vector with all max values, which is debug value.

I can see that the blackboard variable is being updated correctly from my code using the key name, but the id seems to be failing in all cases. This is not just for the GoalLocation vector variable either, it seems to be all of the keys, including vectors, objects and floats.

I have no idea what the issue is, so any help is appreciated.

Thanks,

Hey -

I’ve attempted to setup a project but have not had success reproducing this on my own. If you’re able to reproduce this in a new project, can you attach a copy of the project to help provide additional information for reporting this issue?

Project File

Hi ,

I was able to reproduce the issue in this bare-bones project. The only weird thing I can think of is that it is in UE version 4.9. The issue is the exact same as in my other project, where the id is returning 255.

In this project, it should just print out the blackboard key it is getting and it’s id (which is incorrect) and the value (which is correct because it’s accessed via the key name)

Thanks

Hey -

The .zip file only included a Config, Content, and Source folder. It did not have the .uporject file to open the actual project. Can you try zipping the entire project folder (minus Saved & Intermediate folders) and upload again please?

Hi ,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

Hi ,

Sorry for the delay, I kind of moved on with a hack. Can’t believe I forgot the project file, hopefully this one has everything.link text

After testing that you can build and open that project, it looks like I you just need to drop a B_TestAICharacter in the level to see the printout I was referring to.

Hey ,

When I open the project and add the B_TestAI Character to the level, I see “key name = TestVector, id = 255, value = (-50 , 180 , 138)” printed to the screen. Can you confirm this is what you’re seeing as well as what you expect to see? Additionally, the project you sent does not compile for me in engine versions past 4.9. Can you let me know if you get the same problem in more current engines by opening a copy of the project in 4.12?

Yes that is the output I expected; the problem is the id=255 part since that is the debug id value. I do not have a newer version of the engine downloaded so unfortunately I cannot test it right now, but it would not surprise me if this is only an issue with this older version.

Hey -

There have been multiple fixes applied to AI since 4.9, and it is likely that this has been resolved in a newer engine version. If you’re able to reproduce this in the latest engine (4.12.3) we can investigate further, please provide the setup steps to recreate the issue. For now I will be marking this post as resolved until more information is available.

Cheers

Hey,

Hoping I’m not too late ^^

I ran in the exactly same problem, and after looking into Unreal sources, I found the correct way to add a new blackboard key selector.
You have to initialize your blackboard key selector in your cpp like this:

void UMETA_Decorator_IsInRange::InitializeFromAsset(UBehaviorTree& Asset)
{
    Super::InitializeFromAsset(Asset);

    UBlackboardData* BBAsset = GetBlackboardAsset();
    if (ensure(BBAsset))
    {
        m_RangeBlackboardKey.ResolveSelectedKey(*BBAsset);
        m_SelfLocationBlackboardKey.ResolveSelectedKey(*BBAsset);
    }
}
1 Like

This is the correct answer. Thank you.