# Need help with AI Perception implementation in CPP

**URL:** <https://forums.unrealengine.com/t/need-help-with-ai-perception-implementation-in-cpp/1561454>\
**Category:** C++\
**Tags:** AI-Perception, unreal-engine, CPP, question\
**Created:** [December 26, 2023, 5:56pm UTC](https://forums.unrealengine.com/t/need-help-with-ai-perception-implementation-in-cpp/1561454 "2023-12-26T17:56:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Suman](https://forums.unrealengine.com/u/Suman)\
**Post date:** [December 26, 2023, 5:56pm UTC](https://forums.unrealengine.com/t/need-help-with-ai-perception-implementation-in-cpp/1561454/1 "2023-12-26T17:56:25Z")

</div>

Hey everyone.

I am working on an AI Perception System in CPP with the following function bound to OnPerceptionUpdated.

[![r/UnrealEngine5 - Need help with AI Perception implementation in CPP](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/5/695609e0b6b88297dd9e6409c32266372b965d9d.png)](https://preview.redd.it/vm66su429n8c1.png?width=688&format=png&auto=webp&s=464d84b7babd547734c292d916145dee9ba8b1af)

[![r/UnrealEngine5 - Need help with AI Perception implementation in CPP](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/7/1c7c2ed4f7c93456049863bc5942fb153aaa132b.png)](https://preview.redd.it/kqatghgo8n8c1.png?width=923&format=png&auto=webp&s=76eb3f9941c3b7741f9ba273928e3e4ee22c7edc)

However i am getting a crash whenever i try to start playing in editor. I am using UE5.3.

The stack trace is as follows

[![r/UnrealEngine5 - Need help with AI Perception implementation in CPP](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/5/1/8512e18ec2599c930208cfb89e351fa367c15e25.png)](https://preview.redd.it/9o6riem99n8c1.png?width=1077&format=png&auto=webp&s=e1f7d9b78f53d59bcb7e1c3c3f1cbb20fb9b17bb)

The crash points to this line in CanSenseActor:

**for (FAIStimulus& CurrentStimulus : ActorPerceptionInfo.LastSensedStimuli)**

Can someone please help me understand what i am doing wrong? Every usage i see is similar to this but i keep getting crash and am at my wits end.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [December 26, 2023, 6:21pm UTC](https://forums.unrealengine.com/t/need-help-with-ai-perception-implementation-in-cpp/1561454/2 "2023-12-26T18:21:33Z")

</div>

You should run this in the debugger, which lets you look at the variables in question.

Maybe `GetPerceptionComponent()` returns `NULL`?  
Maybe `LastSensedStimuli` is not present?  
Use “Attach to Process” if you need to debug the game while “running in editor,” or use the launch mode that starts the game as its own process and debug that.

---

<div class="post-metadata">

**Author:** ![Suman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Suman](https://forums.unrealengine.com/u/Suman)\
**Post date:** [December 29, 2023, 2:08pm UTC](https://forums.unrealengine.com/t/need-help-with-ai-perception-implementation-in-cpp/1561454/3 "2023-12-29T14:08:44Z")

</div>

Seems to be an issue with the stack trace line number display. It was a null pointer dereference issue but with another line.  
I was calling SenseClass-\>GetClass() without a nullcheck.

---

<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 29, 2024, 6:39pm UTC](https://forums.unrealengine.com/t/need-help-with-ai-perception-implementation-in-cpp/1561454/4 "2024-01-29T18:39:06Z")

</div>

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