The Tasks I have written in C++ doesn't show up in Behavior Tree

Hello everyone:
I am using UE4.26.2
I am working on Simple Shooter (from UE4 C++ course), the tasks I wrote in C++, I can’t find them in Behavior Tree. Only tasks that are written in Blueprints show up in Behavior Tree.


Kindly help me out,
#unreal #simple-shooter

  1. Could you show your code?
  2. Did it compile successfully?

The .h file

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
#include "ChasePlayer_Task.generated.h"

/**
 *
 */
UCLASS()
class ZOMBIEAPOCALYPSE_API UChasePlayer_Task : public UBTTask_BlackboardBase
{
	GENERATED_BODY()

public:
		UChasePlayer_Task();

	virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;

};

The .cpp file

// Fill out your copyright notice in the Description page of Project Settings.


#include "Tasks/ChasePlayer_Task.h"
#include "AIController.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "AITypes.h"

UChasePlayer_Task::UChasePlayer_Task()
{
	NodeName = "ChasePlayerTask";
}

EBTNodeResult::Type UChasePlayer_Task::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	Super::ExecuteTask(OwnerComp, NodeMemory);
	FVector GoalLocation = OwnerComp.GetBlackboardComponent()->GetValueAsVector(GetSelectedBlackboardKey());

	FAIMoveRequest FAIMoveReq;
	FAIMoveReq.SetGoalLocation(GoalLocation);
	OwnerComp.GetAIOwner()->MoveToLocation(GoalLocation, 1.0f, true, true, true, true, NULL, true);

	return EBTNodeResult::Succeeded;
}

Code did compile successfully.

Could you try a rebuild?
From VS Code with Unreal closed do the following

Ctrl + Shift + B > ProjectNameEditor Platform Development Rebuild

Where ProjectName is the name of your project and Platform is the platform you’re targeting e.g. Win64

Sir I am using VS 2019. I did right click on project name and rebuild it (also tried to rebuild after clean) but still same problem. Engine version 4.26.2.

Oh right that’s because of what you’re search for. The class is called “UChasePlayer_Task” so the task should show up if you search “Chase”

The reason it doesn’t show up in the Behavior Tree is because Unreal Engine requires “BTTask_” in the class name.

Your task is named “ChasePlayer_Task”. If you rename/recreate it to something like “BTTask_ChasePlayer”, keeping “BTTask_” in there, it should show up.

2 Likes

Privacy & Terms