Master AI Perception in Unreal Engine: Detection and Relationships

Master AI Perception in Unreal Engine: Detection and Relationships

Table of Contents

  1. Introduction
  2. Setting up AI Perception
  3. Configuring AI Perception Stimuli Source
  4. Adding Sight Config
  5. Setting up the Mesh
  6. Implementing AI Perception in the Event Graph
  7. Handling Target Perception Updates
  8. Managing Attack Targets
  9. Implementing a Cooldown for Target Forgetting
  10. Addressing Issues with Multiple Targets
  11. Creating a Custom Event to Handle Target Forgetting
  12. Building Relationships with AI Perception
  13. Conclusion

Introduction

In this article, we will explore AI perception within an enemy character. We will learn how to set up AI perception stimuli source and configure sight settings. Additionally, we will implement AI perception in the event graph and handle target perception updates. We will also discuss various techniques for managing attack targets and implementing a cooldown for target forgetting. Furthermore, we will address issues related to multiple targets and build relationships with AI perception. By the end of this article, You will have a solid understanding of AI perception and its implementation in Unreal Engine.

Setting up AI Perception

Before we can start working on AI perception, we need to Create a character. In this tutorial, we will refer to our character as "Enemy Base". To add AI perception to our character, we need to ensure that any actor we want to be perceived also has the AI perception stimuli source. Additionally, we need to enable auto-registering for the AI perception component.

Configuring AI Perception Stimuli Source

To configure AI perception stimuli source, we need to add a sight config to our character. We should also set the dominance since the sight is enabled by default. We need to tick all the necessary boxes in the sight config to enable perception of different stimuli. This will include settings for sight, hearing, and other sensory inputs.

Adding Sight Config

To add the sight config, we can open up the sight config settings and set the necessary values. We should set the mesh for our character and adjust its Height accordingly. This will help with accurate perception of the surroundings. It's important to ensure that the mesh aligns with the capsule component's half height.

Implementing AI Perception in the Event Graph

To implement AI perception in the event graph, we need to add AI perceptions and handle target perception updates. In the event graph, we can create a branch for successful stimulus detection. This branch will determine whether the stimulus is a new detection or a loss of detection. If the stimulus is successfully sensed, we can set the detected actor as the attack target.

Handling Target Perception Updates

When handling target perception updates, we should check if the detected actor is a valid target. If it is not, we can set the attack target and use a print STRING to indicate the attack target has been set. We can also utilize the Blackboard to store the attack target and create a function to handle its setting.

Managing Attack Targets

If there are multiple potential targets, we do not want the AI to continuously switch between targets. To address this, we can implement a check to validate the attack target. We can use the "Is Valid" node to check if the attack target is valid before setting it. If it is not valid, we can set the attack target and use a print string to indicate the attack target has been set.

Implementing a Cooldown for Target Forgetting

By default, the AI character may forget the attack target if it loses sight of it. To prevent this from happening Instantly, we can implement a cooldown timer. We can create a custom event and use a timeline to handle the forgetting time. By setting the forget target time in seconds, we can control the duration before the AI character forgets the target.

Addressing Issues with Multiple Targets

In some situations, the AI character may be following one target while being aware of another. To handle this Scenario, we need to ensure that the AI character does not forget the Current target if it detects a new target. We can achieve this by implementing a check to stop the forgetting process if a new target is detected. This will allow the AI character to focus on the current target.

Creating a Custom Event to Handle Target Forgetting

To create a custom event to handle target forgetting, we can use a timeline. We can set the forget target time as a variable and expose it for customization. By starting the timeline on event begin play, we can trigger the forgetting process after a specified duration. When the timeline finishes, we can set the attack target to null, indicating that the AI character has forgotten the target.

Building Relationships with AI Perception

AI perception can be used to build relationships between characters. By associating a relationship with a class in the AI perception component, we can define how characters perceive each other. By creating an AI relationships enumeration and a variable to store the relationship in our character blueprint, we can determine how our character interacts with other characters Based on their relationship value.

Conclusion

In this tutorial, we have explored the fundamentals of AI perception within an enemy character. We have learned how to set up AI perception stimuli, configure sight settings, and implement AI perception in the event graph. We have also discussed techniques for managing attack targets, implementing a cooldown for target forgetting, and building relationships with AI perception. By applying these concepts, you can create more realistic and engaging enemy characters in your games.

Most people like

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content