해결된 질문
작성
·
125
0
void AABStageGimmick::SpawnRewardBoxes()
{
for (const auto& RewardBoxLocation : RewardBoxLocations)
{
FVector WorldSpawnLocation = GetActorLocation() + RewardBoxLocation.Value + FVector(0.0f, 0.0f, 30.0f);
AActor* ItemActor = GetWorld()->SpawnActor(RewardBoxClass, &WorldSpawnLocation, &FRotator::ZeroRotator);
AABItemBox* RewardBoxActor = Cast<AABItemBox>(ItemActor);
if (RewardBoxActor)
{
RewardBoxActor->Tags.Add(RewardBoxLocation.Key);
RewardBoxActor->GetTrigger()->OnComponentBeginOverlap.AddDynamic(this, &AABStageGimmick::OnRewardTriggerBeginOverlap);
RewardBoxes.Add(RewardBoxActor);
}
}
}
AActor*인 ItemActor 가 가리키는 액터가 월드에서 스폰된 후, 이것을 RewardBoxes.Add(RewardBoxActor); 구문을 통해 약참조 포인터로 참조하도록 한 후 SpawnRewardBoxes() 함수를 종료 하게 되었을 때, 강참조 역할을 했던 해당 객체의 소유권을 갖고있던 지역변수 RewardBoxActor 는 소멸하므로, 강참조 포인터가 파괴됨에 따라 소유권을 가질 능력이 없는 RewardBoxes 안의 WeakPtr 또한 GC의 수집에 의해 더이상 유효하지 않게 될것처럼 느껴지는데 실제론 그렇지 않은 것인가요? 만약 그렇지 않은것이 맞다면 이유가 무엇인지 궁금합니다.
아하.... 확실히 알겠습니다 감사합니다