ue4 小知识点 AIController 重新possessed 以前的pawn 之前的ai继续

比如坐骑 你没坐上之前是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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值