# How to have AI detect collision hits from physical objects

**URL:** <https://forums.unrealengine.com/t/how-to-have-ai-detect-collision-hits-from-physical-objects/1566885>\
**Category:** AI\
**Tags:** Behavior-Tree, hit-detection, ai-controller, unreal-engine, Blueprint, question\
**Created:** [December 28, 2023, 3:11am UTC](https://forums.unrealengine.com/t/how-to-have-ai-detect-collision-hits-from-physical-objects/1566885 "2023-12-28T03:11:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orang\_boi\_m8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Orang\_boi\_m8](https://forums.unrealengine.com/u/Orang_boi_m8)\
**Post date:** [December 28, 2023, 3:11am UTC](https://forums.unrealengine.com/t/how-to-have-ai-detect-collision-hits-from-physical-objects/1566885/1 "2023-12-28T03:11:35Z")

</div>

Okay in my game I want to make it so that when a projectile hits my enemy AI the AI will get stunned for a little moment. However, I can’t seem to get that functionality working for whatever reason.

So this is what I have set up:

- The projectile  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/e/4/4e41a9f65bd82a84f036388b9678f07b7336f088.png)

-All logic and blueprints the NPC is using  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/6/1e6bfbe67e8bc0d0bffc66ba2157af4fe8fc376e.png)

In the character blueprint I made it so whenever the character collides with the projectile it sets a bool to be true.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/a/1/ea1d75600856f346134e1d40302938ff9d6043d5.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/d/1/8d1fef9c80d0577ee96c7be4c941b1a506d0f43d.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/3/7/137d1679c24bcab8c30a963c181fb5e9f8163fac.png)

Then I try to reference the character blueprint in the AI controler to get the “IsStunned” bool and use that as the “Bool Value” for the blackboard bool.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/f/56f8ce7fe930383ccb65c76f1c3c70135b9157be.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/1/4/214c572c37a84f07824e95e97eb333664cddc74c.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/9/ce9c18857f5b175a933fbec5a96d027755bd6595.png)  
(the blackboard key bool is also called “IsStunned” sorry if thats a little confusing)

Then I tried to make it so that the “Stunned” task will run if this bool is true then In the stun task I set the “IsStunned” bool (That is in the character blueprint) to be false.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/f/5cfeb1357325c1569882332e212e59ff8507cd3c.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/7/607035bb7175cebe1858f3f07d3c221319edc978.png)

That didn’t work tho! I think the issue arises when i try to reference the character blueprint in the AI controller blueprint but I don’t know how to fix it.

Do any of you all know how to fix this? Is there a better way to do hit detection that is simple?

I’ve tried looking up some tutorials but they all seem to confusing or not relevant to what I want.

A lot of the tutorials I’ve seen focus on melee combat or line tracing, I don’t reallt want that. All I just want is to make it so when the npc collides with the projectile actor it will stop all tasks, stay still and play the stun animation, then resume its tasks.

For note I am an Unreal Engine 5 beginner (started using it about 3 months ago) that used to use Unity.

---

<div class="post-metadata">

**Author:** ![MrBRight30](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrBRight30](https://forums.unrealengine.com/u/MrBRight30)\
**Post date:** [December 31, 2023, 5:29pm UTC](https://forums.unrealengine.com/t/how-to-have-ai-detect-collision-hits-from-physical-objects/1566885/2 "2023-12-31T17:29:43Z")

</div>

From what I understand I think the problem is here

> [@Orang\_boi\_m8](#):
>
> Then I try to reference the character blueprint in the AI controler to get the “IsStunned” bool and use that as the “Bool Value” for the blackboard bool.

First of all, is there a reason you use “Get all actors of class” instead of using “Get controlled pawn”?  
Secondly, you are setting the “IsStunning” key only on begin play, shouldnt you do it every time it is updated?

---

<div class="post-metadata">

**Author:** ![Orang\_boi\_m8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Orang\_boi\_m8](https://forums.unrealengine.com/u/Orang_boi_m8)\
**Post date:** [December 29, 2024, 12:17pm UTC](https://forums.unrealengine.com/t/how-to-have-ai-detect-collision-hits-from-physical-objects/1566885/3 "2024-12-29T12:17:14Z")

</div>

Hey all I found the solution to my problem its a bit janky but it works.

I just created a service called IsStunned.

 ![Screenshot (256)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/4/74475cce115af81d2786e7cc0e2f0d7edb77d693.png)

Then in Is stunned a tick checks if the IsStunned bool, in NPC\_Goons\_BP, is true and if it is true a black board key is set true.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/a/49a3f3487d20402e4737d748a88293ec9ac4c947.png)

I used a selector to switch from normal patrol and chase to stunned if the blackboard key IsStunned is checked.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/3/0f393f467a45f55bf969e32a323708f89464354c.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/3/9/d39e2be2ce11a6fe281f3644babeaf1d355dc365.png)

So yeah that’s it. Its not the best solution and I haven’t messed with UE5 behaviour tree AIs in a good while so I’m not 100% sure how I managed to fix it but I think this is it.

---

<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:** [January 28, 2025, 12:17pm UTC](https://forums.unrealengine.com/t/how-to-have-ai-detect-collision-hits-from-physical-objects/1566885/4 "2025-01-28T12:17:54Z")

</div>

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