# ビヘイビアツリーによるAIの制御に関する質問

**URL:** <https://forums.unrealengine.com/t/ai/1341470>\
**Category:** 日本語 (Japanese)\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [October 23, 2023, 6:09am UTC](https://forums.unrealengine.com/t/ai/1341470 "2023-10-23T06:09:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![efinkjp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@efinkjp](https://forums.unrealengine.com/u/efinkjp)\
**Post date:** [October 23, 2023, 6:09am UTC](https://forums.unrealengine.com/t/ai/1341470/1 "2023-10-23T06:09:44Z")

</div>

お世話になっております。  
質問させていただきます。

味方キャラクターをAIで操作しています。TargetActorにEnemyというタグを挿入しています。

現在の挙動は、プレイヤーが1体目の敵に近づき攻撃を始めます。攻撃し続けHPが0になると敵はDestoryActorで消滅しますが、味方キャラクターはそのままの場所で攻撃し続けてしまいます。BrackboradのキーはTargetActorがEnemy、inMeleeAttackRangeはTrueを返し続けています。

求めている動作としては基本的にタワーに侵攻し、その途中でAIPerception(視野)で敵を認知したら近づいて攻撃します。攻撃後、視野内に敵がいれば同じ動作、いなければ再度タワーに侵攻します。

お手数をおかけしますがアドバイスをお願いします。

参考

> [@Getting an AI to clear their Target after killing them (simulating physics to ragdoll) using AIPerception?](https://forums.unrealengine.com/t/getting-an-ai-to-clear-their-target-after-killing-them-simulating-physics-to-ragdoll-using-aiperception/434438):
>
> I just recently started learning AIPerception and using it with Blackboard to make an AI capable of team vs team fighting - I’m using On AI Perception Updated and Sight as the primary sense within the AI Controller. Upon an actor successfully sensed, that sensed Actor is set as a blackboard key called TargetActor and I made sure that the AI only sets a new target only if they don’t have a TargetActor set. Because my characters Simulate Physics when they “die” instead of using Destroy Actor, I s…

> **[ARPG開発 011 敵に攻撃をさせる](https://ue5exp0.com/arpg011-enemy_attack/)**
>
> 近づいてきた敵が攻撃してくるようにします。

 ![1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/6/3565f3ca74d834f3c7f6c1dfc9c90c5cabeddbd9.png)  
 ![2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/a/6ba0c53b812e79e6ff1dfd891baab5b5c1dda00f.png)  
 ![3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/2/2f2f23a1eec48119af6bcc302eefc9e4d652581a.png)  
 ![4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/a/d/fad452cfc5e92ebf70ec592e0bf100cd80b9188f.png)

---

<div class="post-metadata">

**Author:** ![efinkjp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@efinkjp](https://forums.unrealengine.com/u/efinkjp)\
**Post date:** [October 24, 2023, 12:11pm UTC](https://forums.unrealengine.com/t/ai/1341470/2 "2023-10-24T12:11:41Z")

</div>

> [@Enemy AI perception does not lose focus when the player is destroyed](https://forums.unrealengine.com/t/enemy-ai-perception-does-not-lose-focus-when-the-player-is-destroyed/464940):
>
> I have my game setup so the AI chases the player on sight (AI Perception). When they “Hit” the player, it causes damage until the player is literally destroyed (Destroy Actor). They do not reset and begin wandering around again. They just stand there where the player last was and spit out this error like there is no tomorrow: Blueprint Runtime Error: “Accessed None trying to read property CallFunc\_GetPlayerCharacter\_ReturnValue”. Blueprint: GetPlayerLocationTut Function: Execute Ubergraph Get…

似たような質問を見つけましたがまだ解決には至っていません。  
色々試してみます。

---

<div class="post-metadata">

**Author:** ![T\_Sumisaki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@T\_Sumisaki](https://forums.unrealengine.com/u/T_Sumisaki)\
**Post date:** [October 24, 2023, 1:13pm UTC](https://forums.unrealengine.com/t/ai/1341470/3 "2023-10-24T13:13:54Z")

</div>

まず条件として

- `TargetActor` に `Enemy` が含まれていたら

とありますが、見たところ `Enemy` を設定しているところはありますが、それ以外の値を設定しているところが見当たりません  
つまり、一度敵が視界に入れば二度と通常状態に戻ることはありません

何らかの方法で攻撃の条件を満たさないようにする必要があります  
具体的には、 `TargetActor` に `Enemy` 以外の値を入れる必要がありますね

---

<div class="post-metadata">

**Author:** ![efinkjp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@efinkjp](https://forums.unrealengine.com/u/efinkjp)\
**Post date:** [October 24, 2023, 4:15pm UTC](https://forums.unrealengine.com/t/ai/1341470/4 "2023-10-24T16:15:36Z")

</div>

T\_Sumisakiさん、コメントありがとうございます。

BTTaskChaseTarget

 ![chasetarget](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/c/5fc824cc2b7970c0dfc342ad00855480a6f18812.png)  
今回の問題ですが、こちらのように組み、敵とタワーにEnemyのTagを入れることで解決できました。さらにMinDistanceを初期値(=99999等の大きい数字)に変更することで

しかし、ご指摘いただいた通り、TargetActorにEnemyが挿入された時に戻すことができません。

AIController\_Ally

 ![aicontroller](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/5/9251dc31cad19ef049967cb5317586cf126757d2.png)  
こちらでうまくいくかなと思いましたが、うまくいきませんでした。

何か方法はございますでしょうか。

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 23, 2023, 4:30pm UTC](https://forums.unrealengine.com/t/ai/1341470/6 "2023-11-23T16:30:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
