BehaviorTree의 currentTime 디버깅

2025. 5. 9. 03:40·Unreal 디버깅

언리얼엔진에서 만약 BehaviorTree AI를 사용했을때

그냥 currentTime을 선언한후 DeltaSeconds에 누적하여 그 currentTime에 따라 task의 실행을 좌우했엇다

 

하지만 이런경우 AI가 여러마리인 경우 CurrentTime의 누적이 일어나 훨씬 빠른

주기를 가져버리는 현상이 일어난다

 

이럴때는 currentTime이 아닌 Struct로 따로 메모리에 변수를 가지고

그변수에 따라 값을 조절하면된다

사용하고있는 태스크에 위쪽에 USTRUCT형식으로 메모리변수를 선언 

USTRUCT()
struct FTaskSkeletonAttackMemory
{
	GENERATED_BODY()

	float structCurrentTime = 0.0f;
	float randomEndTime;
};

 

ExcuteTask에서 초기화를 시켜준뒤

FTaskSkeletonAttackMemory* taskMemory = reinterpret_cast<FTaskSkeletonAttackMemory*>(nodeMemory);
taskMemory->structCurrentTime = 0.0f;

 

TickTask에서 currentTime대신 이 struct에서 선언한 structCurrentTime을 deltaSecond에 누적

	FTaskSkeletonAttackMemory* taskMemory = reinterpret_cast<FTaskSkeletonAttackMemory*>(nodeMemory);
	taskMemory->structCurrentTime += deltaSeconds;

 

조건을 structCurrentTime으로 변경

if (!onceAttackFlag)
{
	if (taskMemory->structCurrentTime > 0.0f)
	{
		skeleton->PlayAttackAnimation();
		onceAttackFlag = true;
		taskMemory->randomEndTime = FMath::FRandRange(2.0f, 3.5f);
	}
}
if (taskMemory->structCurrentTime > taskMemory->randomEndTime)
{
	taskMemory->structCurrentTime = 0.0f;
	onceAttackFlag = false;
	FinishLatentTask(ownerComp, EBTNodeResult::Succeeded);
}

 

이러면 태스크가 Memort안의 변수값으로 각각 AI마다의 별도의 StructCurrentTime을 가집니다

 

결과물

 

--이것을 몰라서 수정하지못하면 AI가 늘어나면 공격주기가 1초도 안되는 현상이 일어난다--

 

'Unreal 디버깅' 카테고리의 다른 글

TActorIterator객체 다수사용  (0) 2025.05.17
Unreal - 텍스처 스트리밍 풀이 예산을 초과했습니다 에러 고치기  (0) 2025.05.15
Unreal - 이동중 낑김현상 sweep부분  (1) 2025.04.25
Unreal - EXCEPTION_ACCESS_VIOLATION 크래시 고치기  (0) 2025.04.10
Unreal - 75퍼센트 무한로딩  (0) 2025.04.10
'Unreal 디버깅' 카테고리의 다른 글
  • TActorIterator객체 다수사용
  • Unreal - 텍스처 스트리밍 풀이 예산을 초과했습니다 에러 고치기
  • Unreal - 이동중 낑김현상 sweep부분
  • Unreal - EXCEPTION_ACCESS_VIOLATION 크래시 고치기
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (130) N
      • Unreal5 프로젝트 다이어리 (73)
      • Unreal5 프로젝트 다이어리2 (9) N
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 다이어리 (24)
        • Stack (3)
        • Hash (4)
        • Heap (2)
        • Sort (4)
        • Exhaustive search (0)
      • 코드 개인보관함 (8)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    언리얼 로딩
    언리얼 모션매칭
    언리얼 behavior tree
    언리얼 시퀀스
    unreal 컷씬
    언리얼 behaviortree
    unreal loading
    unreal look at
    언리얼 로딩창
    언리얼 페이드 아웃
    언리얼 비헤이비어트리
    unreal sequence
    언리얼 foot step
    언리얼 컷씬
    언리얼 motionmatching
    unreal 시퀀스
    언리얼
    unreal 모션매칭
    unreal 로딩
    언리얼 look at
  • hELLO· Designed By정상우.v4.10.3
lucodev
BehaviorTree의 currentTime 디버깅
상단으로

티스토리툴바