Behavior trees and SetBlackboardValueAsBool

Hey everybody,
I think I have a bug I have been stuck for the past few hours:
It seems that SetBlackboardValueAsBool and GetBlackboardValueASBool are not working properly.
When I set a breakpoint in c++ in those functions the KeyName says ‘None’

Would you know if there is anything wrong with my setup?

So this is the task that is calling both functions:

And here is the blackboard

Here is the general tree structure:

Here is the AI controller init:

The tree run fine appart from the fact that the blackboard values are not read nor written properly.
I read that the beh trees are experimental, is that a known bug?

Thanks,

Additional info:
the task portrayed in the screenshot is the SetCurrentPlayer task
The IsTeamTurn decorator is supposed to read this CurrentTeam blackboard value but this is not working either. GetBackboardValueAs bool always returns false because the FName = ‘None’

I can’t see any place where you’re assigning value to the Current Team FBlackboardKeySelector from the first screen. BB selectors are not super slick in terms of BP API so the most reliable way to pick values for them is to expose them to be set as BT node’s property in the BT asset.

It’s not enough to name a FBlackboardKeySelector the same as one of the BB keys.

Also, when building BP-implemented BT decorators you really want to use 4.7 (preview builds already available).

Cheers,

–mieszko

4.7 ? Okay I will try it as soon as it becomes stable.

the most reliable way to pick values for them is to expose them to be set as BT node’s property in the BT asset.

So I should implement a c++ version of that node instead? Using a FBlackboardKeySelector as a property ?

I can’t see any place where you’re assigning value to the Current Team FBlackboardKeySelector from the first screen.
Well there is a SetBlackboardValueAsBool there right?

So I should implement a c++ version of that node instead? Using a FBlackboardKeySelector as a property ?

I’m sorry, I assumed BP usage. C++ rulez and you can do anything with it :wink:

Well there is a SetBlackboardValueAsBool there right?

I meant the key selector variable in your BP, named Current Team in the first screen, doesn’t get it’s value set, so we don’t know which Blackboard key it refers to.

After a while I realised that I was not using parrallels properly so I am using services instead.
Also moving my nodes to c++ completly freed me. Blackboard values are now written and read properly here are details for the community:

The tree

The decorator:

// .h
UCLASS()
class MCST_API UBTDecorator_CheckActiveTeam : public UBTDecorator
{
    GENERATED_UCLASS_BODY()

    /// blackboard key selector 
    UPROPERTY(EditAnywhere, Category=Blackboard)
    struct FBlackboardKeySelector CurrentTeam;

    /// Blueprint interface
    UPROPERTY( EditAnywhere, BlueprintReadWrite, Category="Main" )
    bool TeamA;

    /// Decorator interface
    FString	GetStaticDescription() const override;
    void	InitializeFromAsset(UBehaviorTree& Asset) override;
    bool	CalculateRawConditionValue( UBehaviorTreeComponent * ownerComponent, uint8 * nodeMemory )const override;

};

// .cpp
UBTDecorator_CheckActiveTeam::UBTDecorator_CheckActiveTeam( const class FObjectInitializer & objectInitializer )
    : Super( objectInitializer )
    , CurrentTeam( )
    , TeamA( true )
{

}

void UBTDecorator_CheckActiveTeam::InitializeFromAsset( UBehaviorTree& Asset )
{
    Super::InitializeFromAsset(Asset);
    UBlackboardData* BBAsset = GetBlackboardAsset();
    CurrentTeam.CacheSelectedKey(BBAsset);
}

bool UBTDecorator_CheckActiveTeam::CalculateRawConditionValue( UBehaviorTreeComponent * ownerComponent, uint8 * nodeMemory )const
{
    Super::CalculateRawConditionValue( ownerComponent, nodeMemory );
    UBlackboardComponent* blackboardComp = ownerComponent->GetBlackboardComponent();

    if ( blackboardComp )
    {
	    const bool activeTeam = blackboardComp->GetValueAsBool( CurrentTeam.GetSelectedKeyID() );
	    return activeTeam == TeamA;
    }
    return false;
}

The task:

UBTTaskNode_ChangeActiveTeam::UBTTaskNode_ChangeActiveTeam( const class FObjectInitializer & objectInitializer )
    : Super( objectInitializer )
    , CurrentTeam( )
    , TeamA( true )
{
    bNotifyTick = true;
}

void UBTTaskNode_ChangeActiveTeam::InitializeFromAsset(UBehaviorTree& Asset)
{
    Super::InitializeFromAsset(Asset);
    CurrentTeam.CacheSelectedKey(GetBlackboardAsset());
}

EBTNodeResult::Type UBTTaskNode_ChangeActiveTeam::ExecuteTask(UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory)
{
    UBlackboardComponent* blackboardComp = OwnerComp->GetBlackboardComponent();

    if ( blackboardComp )
    {
	    blackboardComp->SetValueAsBool( CurrentTeam.GetSelectedKeyID(), TeamA );
    }

    return EBTNodeResult::Type::Succeeded;
}