Hi, i’m currently starting work on changing some of my projects blueprint functionalities into C++. I’m starting by making my task nodes in C++ however i’m struggling to find resources to show me how to set up task nodes in C++. I’ve created the task node C++ class but that’s about as far as I’ve got at the moment.
Could someone please show me how to set up a basic BTTaskNode for usage in an editor based Behavior Tree? Or point me to resources that can help me figure this out.
add AIModule and GameplayTasks to your Build.cs file to be able to use the ai module
PublicDependencyModuleNames.AddRange(new string[] {
“Core”,
“CoreUObject”,
“Engine”,
“InputCore”,
“HeadMountedDisplay”,
“AIModule”,
“GameplayTasks”
});
Add AIModule to your uproject if it was not already added
Generate Visual Studio Project Files, to regenerate the needed code
In Unreal create a new C++ class based on BTTaskNode (don’t forget to check “Show all classes” in the class selector otherwise you will not see the BTTaskNode)
override ExecuteTask in your newly created BTTaskNode
e.g.:
MyBTTaskNode.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTTaskNode.h"
#include "MyBTTaskNode.generated.h"
/**
*
*/
UCLASS()
class ANSWERHUBANSWERS_API UMyBTTaskNode : public UBTTaskNode
{
GENERATED_BODY()
public:
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
};
MyBTTaskNode.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyBTTaskNode.h"
EBTNodeResult::Type UMyBTTaskNode::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
UE_LOG(LogTemp, Error, TEXT("Log Some Stuff!"));
return EBTNodeResult::Succeeded;
}