해결된 질문
작성
·
324
0
6강의 ABAT_Trace의 FinalizeTargetActor() 함수에서, 이하와 같이 생성완료된 타겟 액터를 오너 캐릭터의 ASC의 SpawnedTargetActors에 추가했는데, Ability Task가 종료될때 SpawnedTargetActors에서 제거하지 않아도 괜찮을까요?
void UABAT_Trace::FinalizeTargetActor()
{
UAbilitySystemComponent* ASC = AbilitySystemComponent.Get();
if (ASC)
{
const FTransform SpawnTransform = ASC->GetAvatarActor()->GetTransform();
SpawnedTargetActor->FinishSpawning(SpawnTransform);
ASC->SpawnedTargetActors.Push(SpawnedTargetActor);
SpawnedTargetActor->StartTargeting(Ability);
SpawnedTargetActor->ConfirmTargeting();
}
}
혹시나 삭제해야 한다면 타겟 액터 콜백 함수에서 EndTask() 의 실행 직전에 삭제하면 되는지 궁금합니다.
void UABAT_Trace::OnTargetDataReadyCallback(const FGameplayAbilityTargetDataHandle& DataHandle)
{
if (ShouldBroadcastAbilityTaskDelegates())
{
OnComplete.Broadcast(DataHandle);
}
// 추가한 부분
UAbilitySystemComponent* ASC = AbilitySystemComponent.Get();
if (ASC)
{
ASC->SpawnedTargetActors.Remove(SpawnedTargetActor);
}
EndTask();
}
답변 1
1
네. 좋은 질문이십니다.
Target을 Confirm하거나 Cancel하면 타겟 액터 목록은 리셋됩니다.
따라서 별도로 제거할 필요는 없습니다.
void UAbilitySystemComponent::TargetConfirm()
{
// Callbacks may modify the spawned target actor array so iterate over a copy instead
TArray<AGameplayAbilityTargetActor*> LocalTargetActors = SpawnedTargetActors;
SpawnedTargetActors.Reset();
for (AGameplayAbilityTargetActor* TargetActor : LocalTargetActors)
{
if (TargetActor)
{
if (TargetActor->IsConfirmTargetingAllowed())
{
//TODO: There might not be any cases where this bool is false
if (!TargetActor->bDestroyOnConfirmation)
{
SpawnedTargetActors.Add(TargetActor);
}
TargetActor->ConfirmTargeting();
}
else
{
SpawnedTargetActors.Add(TargetActor);
}
}
}
}
void UAbilitySystemComponent::TargetCancel()
{
// Callbacks may modify the spawned target actor array so iterate over a copy instead
TArray<AGameplayAbilityTargetActor*> LocalTargetActors = SpawnedTargetActors;
SpawnedTargetActors.Reset();
for (AGameplayAbilityTargetActor* TargetActor : LocalTargetActors)
{
if (TargetActor)
{
TargetActor->CancelTargeting();
}
}
}
답변 감사합니다!