I’ve done what I thought were the steps to enable behavior tree key setting via C++, but it’s not working… kind of.
See the photo of some of the blackboard keys being set, and some not. Why is this?
Also see photo to see the actor the blackboard is set to is not found in the world when the game is running.
are you initializing a blackboard in c++?
as the way i have achieved this is to create a private variable to hold the blackboard component and initialize it to the character/ai using it then calling the blackboard assigned to the character and i can’t remember off the top of my head but your other issue could be that you are running the behaviour tree before any values are assigned to,
this other suggestion i can make is to do with how you are assuming the player pawn is valid and just inputing this data straight in without performing any checks like i can see you logging the name to check but why not do an if check to see if the player pawn has a location or logging the location to see that you are getting values you are expecting.
i’m still new and make lots of mistakes so i always like to confirm what im expecting in areas that are causing me headaches even if it means 20 logs to find where the bug is.
But like i said make the blackboard component a variable you can set in the editor and use that one
/** Blackboard component for this controller /
UPROPERTY(BlueprintReadWrite, Category = “AI Behavior”, meta = (AllowPrivateAccess = “true”))
class UBlackboardComponent BlackboardComponent;
/** Behavior tree component for this controller */
UPROPERTY(BlueprintReadWrite, Category = "AI Behavior", meta = (AllowPrivateAccess = "true"))
class UBehaviorTreeComponent* BehaviorTreeComponent;
/** To be set in on possess for future ref to minimize casting */
class AGameAICharacter* AICharacter;
class AMainCharacter* BBTargetActor;
// Get the AI Controller
BasicAIController = Cast(GetController());
// Run Behavior Tree
if (BasicAIController)
{
BasicAIController->GetBlackboardComponent()->SetValueAsVector(TEXT(“TargetObjective”), TargetObjectivePoint);
BasicAIController->RunBehaviorTree(BehaviorTree);
}
i did my blackboard and behaviour tree in the controller for the purpose of this but in can go in the pawn file too i believe