Download

AI player controller attribute is empty

Hi,There is a strange question,I created a bot class that inherits the playercharacter class and created it in the game in the following ways but when I try to get the character’s controller in Weapon class, the BOT’s controller is always empty.From the debugging results, the controller of the player character is normal, but the BOT is null.

APlayerAIController* AF09_001GameModeBase::CreatePlayerAIController()
{
	SpawnInfo.Instigator = nullptr;
	SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	SpawnInfo.OverrideLevel = nullptr;

	return GetWorld()->SpawnActor<APlayerAIController>(SpawnInfo);
}

void AF09_001GameModeBase::StartCreatePlayerBot()
{
	APlayerAIController* AIController = nullptr;
	UWorld* World = GetWorld();

	for (FConstControllerIterator It = World->GetControllerIterator(); It;It++) {
		AIController = Cast<APlayerAIController>(*It);
		if(AIController){
			RestartPlayer(AIController);
		    
		}
	}
}
void APlayerCharacter::PostInitializeComponents()
{
	Super::PostInitializeComponents();

	FActorSpawnParameters SpawnInfo;
	SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;//
	CurrentWeapon = GetWorld()->SpawnActor<APlayerWeapon>(PlayerWeaponClass, SpawnInfo);//
	if (CurrentWeapon) {// && WeaponAttachPoint != "" && FPMesh

		CurrentWeapon->SetOwner(this);
		CurrentWeapon->AttachMeshToPawn();
	}
	

}

void APlayerWeapon::SetOwner(APlayerCharacter* AcqOwner)
{
	if (Owner_1 != AcqOwner) {
		Owner_1 = AcqOwner;
		PlayerController = (AHPlayerController*)(Owner_1->GetController());
		if (!PlayerController) {	
                        //
			PlayerAIController = (APlayerAIController*)(Owner_1->GetController());
			 
		}		
	}

}