본문 바로가기
Unreal/AI

[Unreal] TaskNode에서 멤버 변수 사용

by 카피마스터 2023. 1. 29.

UBTTask_Wait 참조

 

1. 사용할 정보를 가지는 구조체를 선언

struct FBTWaitTaskMemory
{
	/** time left */
	float RemainingWaitTime;
};

2. GetInstanceMemorySize를 오버라이딩 하여 해당 구조체 사이즈를 리턴

uint16 UBTTask_Wait::GetInstanceMemorySize() const
{
	return sizeof(FBTWaitTaskMemory);
}

3. 각 멤버 함수들의 인자로 넘어오는 NodeMemory를 정의한 구조체로 캐스팅해서 정보를 사용

EBTNodeResult::Type UBTTask_Wait::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	FBTWaitTaskMemory* MyMemory = (FBTWaitTaskMemory*)NodeMemory;
	MyMemory->RemainingWaitTime = FMath::FRandRange(FMath::Max(0.0f, WaitTime - RandomDeviation), (WaitTime + RandomDeviation));
	
	return EBTNodeResult::InProgress;
}

 

확인 필요

클래스 내에 멤버 변수를 선언하여 사용하는 경우 해당 TaskNode가 속한 BehaviorTree의 모든 BehaviorTreeComponent들이 해당 변수를 공유해서 사용하게 된다.

GetInstanceMemorySize()를 통해 메모리를 할당받아야 인스턴스 각각의 독립적인 메모리 사용이 가능하다.

 

 

 

'Unreal > AI' 카테고리의 다른 글

[Unreal] Decorator Blackboard  (0) 2024.08.04
[Unreal] BehaviorTree 기본 설정  (0) 2023.11.22
[Unreal] Custom TaskNode  (0) 2023.01.16