void AAIController::Possess(APawn* InPawn) { Super::Possess(InPawn); if (!GetPawn()) { return; } // no point in doing navigation setup if pawn has no movement component const UPawnMovementComponent* MovementComp = InPawn->GetMovementComponent(); if (MovementComp != NULL) { UpdateNavigationComponents(); } if (PathFollowingComponent) { PathFollowingComponent->Initialize(); } if (bWantsPlayerState) { ChangeState(NAME_Playing); } OnPossess(InPawn); }
void AAIController::Possess(APawn* InPawn) { // don't even try possessing pending-kill pawns if (InPawn != nullptr && InPawn->IsPendingKill()) { return; } Super::Possess(InPawn); if (GetPawn() == nullptr || InPawn == nullptr) { return; } // no point in doing navigation setup if pawn has no movement component const UPawnMovementComponent* MovementComp = InPawn->GetMovementComponent(); if (MovementComp != NULL) { UpdateNavigationComponents(); } if (PathFollowingComponent) { PathFollowingComponent->Initialize(); } if (bWantsPlayerState) { ChangeState(NAME_Playing); } // a Pawn controlled by AI _requires_ a GameplayTasksComponent, so if Pawn // doesn't have one we need to create it if (CachedGameplayTasksComponent == nullptr) { UGameplayTasksComponent* GTComp = InPawn->FindComponentByClass<UGameplayTasksComponent>(); if (GTComp == nullptr) { GTComp = NewObject<UGameplayTasksComponent>(InPawn, TEXT("GameplayTasksComponent")); GTComp->RegisterComponent(); } CachedGameplayTasksComponent = GTComp; } if (CachedGameplayTasksComponent && !CachedGameplayTasksComponent->OnClaimedResourcesChange.Contains(this, GET_FUNCTION_NAME_CHECKED(AAIController, OnGameplayTaskResourcesClaimed))) { CachedGameplayTasksComponent->OnClaimedResourcesChange.AddDynamic(this, &AAIController::OnGameplayTaskResourcesClaimed); REDIRECT_OBJECT_TO_VLOG(CachedGameplayTasksComponent, this); } OnPossess(InPawn); }