Implement Sensors like Line of Sight and Occlusion in Custom NPC Behaviors

Hi everyone,
I’m trying to understand whether it’s possible to create sensors for an NPC that uses a custom behavior in UEFN.

With the default Guard behavior, the NPC automatically supports things like line of sight, detecting whether the player is visible or occluded.

However, I haven’t found a way to replicate these systems when using a custom behavior.
Is there any method via Verse to implement NPC line of sight and if the player is occluded?

Are these features currently exposed for custom behaviors, or are they exclusive to Guard-type NPCs?

Any insight or workarounds would be greatly appreciated!

Hey @FabioA how are you?

Unfortunately, at this time there is no way to add line of sight that only works if the player is not occluded to a custom behavior.

This is because Verse does not expose functions to make line traces against the geometry of the world, so you cannot detect which objects are between two points. Those functions are exclusive to Guards for now.

The only thing you could do is detect the players only if they are within a proximity radius of the NPC, and have the NPC focus on the player if that condition is met. But with this approach, the NPC would still detect the player even if they are occluded.

Hope this helps you to redesign your feature!

1 Like

I’ve seen that now theres some modules in scene graph that seems to do this kind of things, npc_awareness_component. I’m studying these new features.

Thank you.

1 Like

If you’re using scene graph for your environments, you can try this. Create an entity (Let’s call it X) and give it a mesh that can be traced against using Scene Graph. Set its “entity origin” to the entity that represents the player. You can get the entity that represents the player by grabbing the fort_character interface off of the player and calling GetEntity.

Then entity X will move with the player. I have done this before so I know it works. Since entity X moves with the player, you can trace against entity X.