# UE4 AI??-shooterGame??AI??

**URL:** <https://forums.unrealengine.com/t/ue4-ai-shootergame-ai/1320>\
**Category:** 简体中文 (Simplified Chinese)\
**Tags:** unreal-engine\
**Created:** [March 29, 2014, 12:25pm UTC](https://forums.unrealengine.com/t/ue4-ai-shootergame-ai/1320 "2014-03-29T12:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_86937c97](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86937c97](https://forums.unrealengine.com/u/anonymous_user_86937c97)\
**Post date:** [March 29, 2014, 12:25pm UTC](https://forums.unrealengine.com/t/ue4-ai-shootergame-ai/1320/1 "2014-03-29T12:25:06Z")

</div>

@???  
@2014.3.29  
???ShooterAIController.cpp???,???.  
???bot?,???bot???,?UE4??Controller??APawn?,???UE3???.???Possess???,???].???:  
AShooterAIController::AShooterAIController(constclass FPostConstructInitializeProperties& PCIP) : Super(PCIP)  
{  
BlackboardComp= PCIP.CreateDefaultSubobject\<UBlackboardComponent\>(this, TEXT(“BlackBoardComp”));  
BehaviorComp= PCIP.CreateDefaultSubobject\<UBehaviorTreeComponent\>(this, TEXT(“BehaviorComp”));  
bWantsPlayerState= true;  
}  
???,???.??,???,???”?”??.  
void AShooterAIController::Possess(APawn_InPawn)  
{  
Super::Possess(InPawn);  
AShooterBot_Bot = Cast\<AShooterBot\>(InPawn);  
//start behavior  
if(Bot && Bot-\>BotBehavior)  
{  
BlackboardComp-\>InitializeBlackboard(Bot-\>BotBehavior-\>BlackboardAsset);  
EnemyKeyID= BlackboardComp-\>GetKeyID(“Enemy”);  
NeedAmmoKeyID= BlackboardComp-\>GetKeyID(“NeedAmmo”);  
BehaviorComp-\>StartTree(Bot-\>BotBehavior);  
}  
}  
???possess??,???,???.  
Bot ? Bot-\>BotBehavior,Bot??NPC???, Bot-\>BotBehavior???,???,???.  
class AShooterBot : public AShooterCharacter  
{  
GENERATED\_UCLASS\_BODY()  
UPROPERTY(EditAnywhere,Category=Behavior)  
classUBehaviorTree\* BotBehavior;  
virtualbool IsFirstPerson() const OVERRIDE;  
virtualvoid FaceRotation(FRotator NewRotation, float DeltaTime = 0.f) OVERRIDE;  
};  
???:

[http://xiangce.baidu.com/picture/detail/e37108dc59e9f34ba5b774b8eccf7fd6de2a907b?from=dialog](http://xiangce.baidu.com/picture/detail/e37108dc59e9f34ba5b774b8eccf7fd6de2a907b?from=dialog)

???,???,???.

???,???,???,???Map,???,??UE4???,???.???.???.

[http://xiangce.baidu.com/picture/detail/3b0e4f32ab359f07af7203a9a34ec7188b4ce67b?from=dialog](http://xiangce.baidu.com/picture/detail/3b0e4f32ab359f07af7203a9a34ec7188b4ce67b?from=dialog)

??,???,???.  
void AShooterAIController::CheckAmmo(constclass AShooterWeapon\* CurrentWeapon)  
{  
……  
BlackboardComp-\>SetValueAsBool(NeedAmmoKeyID,(Ratio \<= 0.1f));  
}  
void AShooterAIController::SetEnemy(classAPawn\* InPawn)  
{  
…  
BlackboardComp-\>SetValueAsObject(EnemyKeyID,InPawn);  
}  
class AShooterCharacter\* AShooterAIController::GetEnemy()const  
{  
…  
returnCast\<AShooterCharacter\>(BlackboardComp-\>GetValueAsObject(EnemyKeyID));  
}  
??,???NPC???,???UE3?FSM.???Tick???,???.

that’s all,thank you!

---

<div class="post-metadata">

**Author:** ![mamoniem](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mamoniem/32/1194698_2.png) [@mamoniem](https://forums.unrealengine.com/u/mamoniem)\
**Post date:** [August 5, 2014, 4:23pm UTC](https://forums.unrealengine.com/t/ue4-ai-shootergame-ai/1320/2 "2014-08-05T16:23:26Z")

</div>

and what is the problem ? and what is all this “???” I assume it is code comments in Chinese !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c2782329](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c2782329](https://forums.unrealengine.com/u/anonymous_user_c2782329)\
**Post date:** [December 5, 2014, 1:34am UTC](https://forums.unrealengine.com/t/ue4-ai-shootergame-ai/1320/3 "2014-12-05T01:34:04Z")

</div>

void AShooterAIController::Possess(APawn\*InPawn)

{

```
     Super::Possess(InPawn);

     AShooterBot*Bot = Cast&lt;AShooterBot&gt;(InPawn);

     //start behavior

     if(Bot && Bot-&gt;BotBehavior)

     {

               BlackboardComp-&gt;InitializeBlackboard(Bot-&gt;BotBehavior-&gt;BlackboardAsset);

               EnemyKeyID= BlackboardComp-&gt;GetKeyID("Enemy");

               NeedAmmoKeyID= BlackboardComp-&gt;GetKeyID("NeedAmmo");

               BehaviorComp-&gt;StartTree(Bot-&gt;BotBehavior);

     }

```

}

this is UE4 c++ code AIcontoller Possess (this code is in shootergame project)  
this AI is normal untill UE4.6  
when I upgrade to 4.6 , compile error

this code have error  
BehaviorComp-\>StartTree(Bot-\>BotBehavior);

any one know how to fix it?
