Enhance AI Perception with Sight Sense in Unreal Engine

Enhance AI Perception with Sight Sense in Unreal Engine

Table of Contents

  1. Introduction
  2. Setting up the AI Controller
  3. Setting up the Enemy Character
  4. Adding the Perception Component
  5. Setting up the AI Perception Component
  6. Configuring the Senses
  7. Using the Gameplay Debugger
  8. Implementing Perception in Blueprints
  9. Customizing Perception Behavior
  10. Using Event Handlers for Perception Updates

📚 Introduction

Welcome back, everyone! In this video, we will be adding the perception component to our project and setting up our first sense, which will be sight. So let's dive right into it!

🎮 Setting up the AI Controller

First, we need to create a new AI controller. To do this, let's create a new blueprint class and name it "AIController". In the blueprint, go to the Event Graph and search for the "Event Possessed" event. Cast the possessed pawn to our enemy character blueprint and store it as a variable. Create another variable to store the enemy player pawn. Make sure you fill in the correct class for the player pawn. Connect everything and save the blueprint.

🧟‍♂️ Setting up the Enemy Character

Next, let's open the blueprint for our enemy character (in this case, the zombie). Disconnect the "Event Begin Play" and "Delay" nodes. Search for the "Event Process Possessed" event and cast it to our custom AI controller. Store the AI controller as a variable. Make sure to connect the nodes properly. Set the enemy player pawn in the AI controller. Finally, in the Class Defaults of the character, set the AI controller class to the newly created controller.

👁️‍🗨️ Adding the Perception Component

Now let's add the perception component to our AI controller. In the Blueprint Editor, click on "Add Component" and search for "AI Perception Component". Set up the perception component by adding the sight sense. Configure the default settings such as the sight radius and the loose sight radius. Set the peripheral vision half angle degrees and enable the necessary affiliations for detection. You can also adjust other settings such as the auto success range and the maximum age. Once you're done, compile and save the blueprint.

🔍 Setting up the AI Perception Component

To enable the gameplay debugger, go to the project settings and navigate to the gameplay debugger tab. Change the activation key to a valid keybind. Now, in-game, you can enable the gameplay debugger to see visualized information about the perception component. With the gameplay debugger enabled, you can use the numpad numbers to activate or disable specific categories. To visualize the perception component, enable the perception category. You can now see the sight radius, loose sight radius, and peripheral vision half angle cone in-game.

🎮 Configuring the Senses

To utilize the perception component in Blueprints, we can use the "On Perception Updated" event and the "On Target Perception Updated" event. These events return the perceived actor and the stimulus struct, which contains information about the perception. We can use a branch to check if the perceived actor is our enemy and if the sense is sight. If true, we can retrieve the necessary information and perform actions such as starting or stopping the chase. Additionally, we can use the "Get Currently Perceived Actors" and "Get Known Perceived Actors" functions to retrieve the actors that are currently or previously perceived.

📊 Using the Gameplay Debugger

The gameplay debugger is a useful tool to Visualize the perception component in action. By enabling the perception category, you can see the sight radius, loose sight radius, and peripheral vision half angle cone in-game. You can also enable or disable specific categories using the numpad numbers. This allows you to focus on specific aspects of the perception component and reduce clutter on the screen.

🧪 Implementing Perception in Blueprints

The perception component provides events and functions to implement perception behavior in Blueprints. By utilizing the "On Perception Updated" event, we can retrieve information about the perceived actor and the stimulus struct. We can use this information to determine if the perceived actor is our enemy and which sense was triggered. With this knowledge, we can perform specific actions based on the perception, such as starting or stopping the chase. Additionally, we can use the "Get Currently Perceived Actors" and "Get Known Perceived Actors" functions to retrieve Relevant actors for further processing.

👀 Customizing Perception Behavior

In order to customize perception behavior, you can adjust the settings of the perception component. This includes modifying the sight radius, loose sight radius, and peripheral vision half angle degrees to suit your specific needs. You can also change the auto success range from the last seen location and the maximum age settings. These settings allow you to fine-tune the perception behavior and tailor it to your Game's requirements.

🎛️ Using Event Handlers for Perception Updates

The perception component provides two events, "On Perception Updated" and "On Target Perception Updated", to handle perception updates. The "On Perception Updated" event returns an array of updated actors and their associated stimuli. With this event, you can iterate through the array and filter out specific stimuli, such as the sight sense. This allows you to process the information in a more granular and customizable way. The "On Target Perception Updated" event, on the other hand, only returns the last perception update for a specific actor.

✨ Highlights

  • Set up the AI controller and enemy character blueprints.
  • Add the perception component to the AI controller.
  • Configure the sight sense in the perception component.
  • Use the gameplay debugger to visualize the perception component.
  • Implement perception behavior in Blueprints using events and functions.
  • Customize perception behavior by adjusting various settings.
  • Utilize event handlers for perception updates.

👥 FAQ

Q: Can I use multiple senses in the perception component? A: Yes, you can add multiple senses to the perception component and configure them individually.

Q: Can I customize the perception behavior for different enemy types? A: Absolutely! By adjusting the settings and utilizing the event handlers, you can customize the perception behavior for different enemy types.

Q: How can I optimize the perception component for performance? A: You can optimize the perception component by fine-tuning the settings, reducing the maximum age, and limiting the number of perceived actors.

Q: Can I use the perception component in multiplayer games? A: Yes, the perception component can be used in multiplayer games. However, you may need to handle replication and synchronization of the perceived actors and stimuli.

Q: Are there any limitations to the perception component? A: The perception component has certain limitations, such as the inability to perceive objects behind obstacles or handle complex scenarios. It is important to test and iterate on your implementation to ensure it meets your requirements.

🌐 Resources

That's it for this video! If you enjoyed it or found it helpful, please consider leaving a like. See you in the next one!

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