[Unreal]#18_Custom Behavior Tree Task
Unreal 개발 중 "Behavior Tree Task"에 대해 알아보겠습니다.
"Simple Shooter Game"의 AI Player 개발 내용입니다.
BTTask_Shoot
1. BTTask_Shoot
2. UBTTask_Shoot.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTTaskNode.h"
#include "BTTask_Shoot.generated.h"
/**
*
*/
UCLASS()
class SIMPLESHOOTERNEW_API UBTTask_Shoot : public UBTTaskNode
{
GENERATED_BODY()
public:
// 1. 생성자
UBTTask_Shoot();
protected:
// 2. UBTTaskNode::Execute() 가상 함수 오버라이딩
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
};
3. UBTTask_Shoot.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BTTask_Shoot.h"
#include "AIController.h"
#include "ShooterCharacter.h"
UBTTask_Shoot::UBTTask_Shoot()
{
NodeName = "Shoot";
}
EBTNodeResult::Type UBTTask_Shoot::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
Super::ExecuteTask(OwnerComp, NodeMemory);
// 1. AIController 가져오기
if(OwnerComp.GetAIOwner() == nullptr)
return EBTNodeResult::Failed;
// 2. APawn -> AShooterCharacter Casting
AShooterCharacter* Character = Cast<AShooterCharacter>(OwnerComp.GetAIOwner()->GetPawn());
if(Character == nullptr)
return EBTNodeResult::Failed;
else
Character->Shoot();
return EBTNodeResult::Succeeded;
}
- 생성자 : 노드 네임 설정
- GetAIOwner() : AAIController 유형의 AI를 소유하는 AI Controller를 반환합니다.
- GetPawn() : AIController의 함수가 아니라, AIController가 상속하는 AController의 함수입니다!
- AShooterCharacter::Shoot() : 범위 지정자가 꼭 "public"인지 확인해야 합니다!
Behavior Tree
1. BTTask_Shoot 추가
2. 테스트
'게임개발 > Unreal C++' 카테고리의 다른 글
[Unreal]#20_Log (0) | 2022.11.02 |
---|---|
[Unreal]#19_Custom Behavior Tree Service (0) | 2022.10.05 |
[Unreal]#17_Behavior Tree (1) | 2022.10.04 |
[Unreal]#16_Behavior Tree Setting (0) | 2022.10.02 |
[Unreal]#15_Line Of Sight, Acceptance Radius of AI (0) | 2022.10.02 |