比如坐骑 你没坐上之前是AIC控制的 你坐上之后 pc控制坐骑,aic让位不控制这个坐骑。然后你下坐骑之后,aic重新控制坐骑,你希望之前的ai的 bb和bt继续运转,只需要在possessed坐骑之前需要设置bStartAILogicOnPossess为true
/** By default AI's logic does not start when controlled Pawn is possessed. Setting this flag to true
* will make AI logic start when pawn is possessed */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
uint32 bStartAILogicOnPossess : 1;
因为在aic中
void AAIController::OnPossess(APawn* InPawn)
{
// don't even try possessing pending-kill pawns
if (InPawn != nullptr && InPawn->IsPendingKill())
{
return;
}
Super::OnPossess(InPawn);
if (GetPawn() == nullptr || InPawn == nullptr)
{
return;
}
// not calling UpdateNavigationComponents() anymore. The PathFollowingComponent
// is now observing newly possessed pawns (via OnNewPawn)
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);
}
if (Blackboard && Blackboard->GetBlackboardAsset())
{
InitializeBlackboard(*Blackboard, *Blackboard->GetBlackboardAsset());
}
//看这里如果你不设置为true是不会运行startlogic的也就是说不会运行ai行为树等
if (bStartAILogicOnPossess && BrainComponent)
{
BrainComponent->StartLogic();
}
}
因此在possessed之前需要 设置aic的 bStartAILogicOnPossess 为true