Intro

Before starting a getting started guide, I would like to mention that the plugin comes with a working sample game that is available inside the plugin’s directory. To play the example labirynth mini game and view example assets head to Sample Content page for detailed description.

This page will go through steps required to setup advanced sight plugin from scratch using a third person template game in Unreal Engine 5.4.

The plugin can be used in a none-code projects. It contains all required classes and functions exposed to blueprints to use, no need to write any C++ if you don’t want to.

Please note that the steps below are blueprint based but whenever a component is added to a blueprint, or a new blueprint is created, remember that this might as well be a new C++ subclass or a component created in a C++ class.

Project Settings

Make sure to take a look at the plugin’s settings inside Project Settings window. If you have already part of your game ready and you are migrating from a different sight system make sure you update Advanced Sight Collision Channel to the one you used for visibility checks. By default the system uses WorldStatic collision channel.

Feel free to play with colors and details of debug drawings as well to match your personal preference or needs if your game uses specific color palette making default colors hard to see.

ProjectSettings

AIController

Let us begin by creating an AIController subclass that will be controlling our AI agent. Right click in Content Browser and press Blueprint Class. Then search for AIController.

Create AI Controller blueprint

Once new AIController subclass blueprint is created and opened, head to the Components panel (usually on the left hand side of the blueprint editor) and press Add button. Search for Advanced Sight Component.

Add Advanced Sight Component to AI Controller

Please notice that there are two components with very similar names. One is Advanced Sight Component and the other is Advanced Sight Target Component. Make sure you select Advanced Sight Component in this step.

Now let’s create a data asset for the advanced sight component defining all the perception details. Head to Content Browser once again and press RMB, go to Miscellanous category and select Data Asset.

Create Data Asset

In a window that will appear in front, search for Advanced Sight Data. Then select it and press Select button.

Choose Data Asset type

Once created and opened following window should be visible:

Data Asset Opened

Please note that a lot of properties have additional comment visible when you keep your mouse hovered on a selected property.

For this project I will add two sight infos structs, one that will cover long distance 90 degrees view in front of an agent, and second that will be short range but 360 degrees around the agent. I’ll also udpate the debug color so they distinguishable later when we use debug tools. The data asset configuration should look like this:

Data Asset Configured

Final step in the data asset configuration is to set the detection by affiliation flags. Expand the property and tick Detect Enemies.

Now go back to the AIController blueprint we created before, select AdvancedSight component and in the Details panel find SightData property. Then set it’s value to the new config we just created and configured.

There are more properties but we don’t need to worry about them for the basic setup. To learn more about remaining properties please refer to the API page or read comment for each property visible when hovering mouse cursor on top of the property’s name.

Last thing to note is that the AdvancedSight exposes few events that are extremelly useful in implementing custom logic. Those events can be found under Events category in the details panel when AdvancedSight component is selected.

Advanced sight component events

Press + button next to any of the On Target Spotted, On Target Perceived, On Target Lost and On Target Forgotten and hook them with a simple print string function to better understand when each of the event’s is called. For more details on how events work refer to the diagram in the Overview page.

Target Character

Each target actor that is either a listener (owner of the advanced sight component) or a target must do one of the three things:

  • implement IGenericTeamAgentInterface which is a built-in Epic’s interface that can only be implemented directly in C++.
  • inherit from Advanced Sight Character class which already implements the above mentioned plugin
  • add Advanced Sight Team component to the actor Both Advanced Sight Character and Advanced Sight Team component already contain a Team Id property that must simply be set to appropriate value in blueprint defaults. This ensures that you don’t have to make any C++ changes in case you are already using different base C++ class for your actor/character and can’t inherit from Advanced Sight Character and you also can’t implement IGenericTeamAgentInterface yourself.

If you already have a character blueprint in your project and would like to use AdvancedSightCharacter for as your base class you can reparent your blueprint by opening a blueprint asset, selecting File in the top left corner and selecting Reparent Blueprint.

Reparenting Blueprint

Keep in mind that both player character as well as NPC characters must implement IGenericTeamAgentInterface. This is because based on the TeamId property the system is generating appropriate queries. If two agents are from the same team and the advanced sight config defined that it only cares about enemies, it will not be querying for any other agent with the same TeamId.

If you use C++, remember to add AdvancedSight module reference to your game module’s *.build.cs file. If you are getting unresolved external symbol errors despite adding AdvancedSight module to the PublicDependencyModuleNames you must also add AIModule module.

Third person template game comes with a BP_ThirdPersonCharacter plugin which needs to be reparented as described above. Once reparented, in class default properties you should be able to find Advanced Sight category with TeamId property. It’s default value is 255 which is invalid value on purpose. Update the value to i.e. 1.

TeamIdProperty updated value

Next, open character’s Class Settings, navigate to Interfaces category and press Add button. In the expanded list find AdvancedSightTarget interface and select it.

AdvancedSightTarget interface implemented in character blueprint

There should be new function now visible inside the My Blueprint tab under Interfaces category called Get Visibility Point Components.

AdvancedSightTargetInterfaceFunction

Now, select your character’s main mesh component, press Add button and add Scene Component as a child component to the mesh component. Name it however you want, I called mine TargetPoint_Head.

Head target point

With the new scene component is selected, head to details panel. Under Sockets category, set Parent Socket property to a head bone to attach the component to that bone.

Setting target point socket

Repeat above steps and create two more scene components for left and right hand. Don’t forget to attach them to appropriate bones.

Next, double click the interface function name in the My Blueprint tab. It should open blueprint editor with the following content:

Empty editor blueprint for interface function

This interface function is used to fetch the references to the visibility points. We need to create an array and assign all created sight points to it. This is fairly easy operation. Final function should look like this:

Implemented interface function

Last step for the character setup is to attach Advanced Sight Target actor component.

Advanced Sight Target component attached

Make sure you use Advanced Sight Target component, not the Advanced Sight component which we used when setting up AIController.

That’s it, there are no extra properties to set in the component, our character is set and ready to play.

Verification

To verify everything works fine we will use the ThirdPersonMap and set a simple testing scenario. Add new character to the scene by dragging and dropping the character’s blueprint we created above on a scene.

Character on a scene

Inside details panel of the character, find Pawn category and make sure that Auto Possess AI is set to Placed in World and update AI Controller Class property to the AI controller we created at the very beginning.

Override AI controller class

Now search for TeamId property and change it to a different number between 2 and 254 inclusively. In this example I set it to 2. This is necessary step to ensure that system treat player character and NPC character as enemies and thus will generate sight queries for them.

Updating TeamId for NPC character

Before starting PIE (Play In Editor) make sure that the NPC character is facing towards the Player Start actor. Then proceed and start PIE. The game should start without any issues. Now to see what’s happening under the hood we need to enable debugging tool. To do this press ~ (key might differ based on your local keyboard layout) to open console command prompt and type AdvancedSight.ShouldDebugDrawBasic 1. This should enable debug drawing and the game viewport will look like this:

Debug drawing for advanced sight

Notice that colors used here in the debug drawing matches the colors we defined in the sight config data asset in the beginning of this getting started guide.

Walk into the sight range and notice that spheres matching the visibility points locations immediately appear and there is a line of sight drawn from the NPC character towards each of them.

Visibility points debug visualization

For details on how to properly use debug visualization refer to a Debug page.

If your game viewport looks similar it means you setup everything correctly and are ready to implement your own logic! Have fun!