Get/Set native Enum blackboard type won't compile

Hi All

I have an Enum in a C++ AI controller that I’m using in a blackboard. I have the header

#include "BehaviorTree/Blackboard/BlackboardKeyType_Enum.h"

In the AI Controller. As well as the enum;

enum class EBehaviorType : uint8

	Indifferent	       UMETA(DisplayName = "Indifferent"),
	Receptive            UMETA(DisplayName = "Receptive"),
	Chat                      UMETA(DisplayName = "Chat"),
	GoSomewhere        UMETA(DisplayName = "GoSomewhere"),
	Hostile                UMETA(DisplayName = "Hostile"),
	Fight                    UMETA(DisplayName = "Fight")


In the blackboard the key type is Enum and writing EBahaviorType in the Enum name causes it to appear in EnumType and the Is Enum Name Valid box to be automatically ticked.

However, if I write, for example;

BlackboardComp->SetValue<UBlackboardKeyType_Enum>(ModeID, NewBehaviorType);

In a function which is passing in a new EBehaviorType, it won’t compile. I get the following error;

   Error	1	error C2664: 'bool UBlackboardComponent::SetValue<UBlackboardKeyType_Enum>(FBlackboard::FKey,UBlackboardKeyType_Enum::FDataType)' : cannot convert argument 1 from 'int32' to 'const FName &'	

Is this a bug?


EDIT: I added the line

const FName& ModeName = BlackboardComp->GetKeyName(ModeID);

And used that instead of the keyID as the first argument passed to SetValue. Now the error is;

Error	1	error C2664: 'bool UBlackboardComponent::SetValue<UBlackboardKeyType_Enum>(FBlackboard::FKey,UBlackboardKeyType_Enum::FDataType)' : cannot convert argument 2 from 'EBehaviorType' to 'UBlackboardKeyType_Enum::FDataType'

This seems to be completely broken? I just created a variable in the AI controller of type EBehaviorType. I figured I could get and set that variable and adjust the key value in the blackboard from BP’s. In debugging the blackboard tasks etc where I’m trying to get or set the blackboard value from BP, it has no value. I can retrieve the EBehaviorType value from the AI controller, but I cant get or set it on the blackboard from BP’s either.


Great, thanks! Sorry- didnt realize I’d put it in the wrong section…

Hi robbie,

I’ve moved this to the Bug Reports section (sorry, I don’t typically have enough time to look through the C++ section for folks needing help) and assigned myself to the issue. I’ll take a look at this as soon as I can.

I think I’m running into the same problem, except with an Enum created in the Content Browser (so entirely BP based). Setting the value manually (by not using an Enum as LIteral Node and just plugging in the index) works, but as soon as I hook up the Literal node it doesn’t seem to get the right result.

Well, the compilation error message tells you exactly what’s wrong. Instead of using your enum value directly in call to UBlackboardComponent::SetValue() you need to cast it to UBlackboardKeyType_Enum::FDataType (which is uint8 in practice, if you don’t want to type too much). So you’ll end up with a call like this:

BlackboardComp->SetValue<UBlackboardKeyType_Enum>(ModeName, static_cast<UBlackboardKeyType_Enum::FDataType>(NewBehaviorType));

I have no idea why compiler complains about not being able to convert enums to uint8, even if you declare your enum as uint8 enum class (like you did).

BTW, I strongly encourage you to use UBlackboardComponent::SetValue function family that uses FBlackboard::FKey as the first param. It’s a lot faster.



Ah ok, thanks!. I thought I’d read somewhere that the enum value is supposed to be converted to binary automatically and that that is what is used to get and set. Maybe I imagined that…