bool UAbilityTask_WaitTargetData::BeginSpawningActor(UObject* WorldContextObject, TSubclassOf<AGameplayAbilityTargetActor> InTargetClass, AGameplayAbilityTargetActor*& SpawnedActor) { SpawnedActor = nullptr; if (Ability) { if (ShouldSpawnTargetActor()) { UClass* Class = *InTargetClass; if (Class != NULL) { UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject); SpawnedActor = World->SpawnActorDeferred<AGameplayAbilityTargetActor>(Class, FTransform::Identity, nullptr, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn); } if (SpawnedActor) { TargetActor = SpawnedActor; InitializeTargetActor(SpawnedActor); } } RegisterTargetDataCallbacks(); } return (SpawnedActor != nullptr); }
bool UAbilityTask_WaitTargetData::BeginSpawningActor(UObject* WorldContextObject, TSubclassOf<AGameplayAbilityTargetActor> InTargetClass, AGameplayAbilityTargetActor*& SpawnedActor) { SpawnedActor = nullptr; if (Ability.IsValid()) { if (ShouldSpawnTargetActor()) { UClass* Class = *InTargetClass; if (Class != NULL) { UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject); SpawnedActor = World->SpawnActorDeferred<AGameplayAbilityTargetActor>(Class, FVector::ZeroVector, FRotator::ZeroRotator, nullptr, nullptr, true); } if (SpawnedActor) { TargetActor = SpawnedActor; InitializeTargetActor(SpawnedActor); } } RegisterTargetDataCallbacks(); } return (SpawnedActor != nullptr); }
void UAbilityTask_WaitTargetData::Activate() { // Need to handle case where target actor was passed into task if (Ability && (TargetClass == nullptr)) { if (TargetActor) { AGameplayAbilityTargetActor* SpawnedActor = TargetActor; TargetClass = SpawnedActor->GetClass(); RegisterTargetDataCallbacks(); if (IsPendingKill()) { return; } if (ShouldSpawnTargetActor()) { InitializeTargetActor(SpawnedActor); FinalizeTargetActor(SpawnedActor); // Note that the call to FinalizeTargetActor, this task could finish and our owning ability may be ended. } else { TargetActor = NULL; // We may need a better solution here. We don't know the target actor isn't needed till after it's already been spawned. SpawnedActor->Destroy(); SpawnedActor = nullptr; } } else { EndTask(); } } }