void AController::Possess(APawn* InPawn) { if (!HasAuthority()) { FMessageLog("PIE").Warning(FText::Format( LOCTEXT("ControllerPossessAuthorityOnly", "Possess function should only be used by the network authority for {0}"), FText::FromName(GetFName()) )); return; } REDIRECT_OBJECT_TO_VLOG(InPawn, this); if (InPawn != NULL) { if (GetPawn() && GetPawn() != InPawn) { UnPossess(); } if (InPawn->Controller != NULL) { InPawn->Controller->UnPossess(); } InPawn->PossessedBy(this); SetPawn(InPawn); // update rotation to match possessed pawn's rotation SetControlRotation( Pawn->GetActorRotation() ); Pawn->Restart(); } }
void ANavLinkProxy::BeginPlay() { UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(GetWorld()); if (NavSys) { REDIRECT_OBJECT_TO_VLOG(this, NavSys); } Super::BeginPlay(); }
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); }
FAISenseID UAIPerceptionSystem::RegisterSenseClass(TSubclassOf<UAISense> SenseClass) { check(SenseClass); FAISenseID SenseID = UAISense::GetSenseID(SenseClass); if (SenseID.IsValid() == false) { UAISense* SenseCDO = GetMutableDefault<UAISense>(SenseClass); SenseID = SenseCDO->UpdateSenseID(); if (SenseID.IsValid() == false) { // @todo log a message here return FAISenseID::InvalidID(); } } if (SenseID.Index >= Senses.Num()) { const int32 ItemsToAdd = SenseID.Index - Senses.Num() + 1; Senses.AddZeroed(ItemsToAdd); #if !UE_BUILD_SHIPPING DebugSenseColors.AddZeroed(ItemsToAdd); #endif } if (Senses[SenseID] == nullptr) { Senses[SenseID] = NewObject<UAISense>(this, SenseClass); check(Senses[SenseID]); bHandlePawnNotification |= Senses[SenseID]->ShouldAutoRegisterAllPawnsAsSources() || Senses[SenseID]->WantsNewPawnNotification(); if (Senses[SenseID]->ShouldAutoRegisterAllPawnsAsSources()) { UWorld* World = GetWorld(); if (World->HasBegunPlay()) { RegisterAllPawnsAsSourcesForSense(SenseID); } // otherwise it will get called in StartPlay() } #if !UE_BUILD_SHIPPING DebugSenseColors[SenseID] = Senses[SenseID]->GetDebugColor(); PerceptionDebugLegend += Senses[SenseID]->GetDebugLegend(); // make senses v-log to perception system's log REDIRECT_OBJECT_TO_VLOG(Senses[SenseID], this); UE_VLOG(this, LogAIPerception, Log, TEXT("Registering sense %s"), *Senses[SenseID]->GetName()); #endif } return SenseID; }
void AAIController::PostInitializeComponents() { Super::PostInitializeComponents(); if (bWantsPlayerState && !IsPendingKill() && (GetNetMode() != NM_Client)) { InitPlayerState(); } #if ENABLE_VISUAL_LOG TArray<UActorComponent*> ComponentSet; GetComponents(ComponentSet); for (auto Component : ComponentSet) { REDIRECT_OBJECT_TO_VLOG(Component, this); } #endif // ENABLE_VISUAL_LOG }