Actor comparing reference to self for NPC detection

Hi,

I have a project that has hit a bit of a stumbling block and I maybe misunderstanding the logic behind it.

In my project I have AI NPCs that use the AI Perception sight sense to recognise the player or other NPCs. Once the NPC has seen the player or an NPC for the first time it adds them to a list of know characters and tracks there details (name, personality, opinion currently). At this stage an NPC can recognise the player and adds it to the list it also checks if the detected player is already on the list and doesn’t add it if it is already there. It doesn’t work that way with other NPCs, NPC1 will detect NPC2 and add it to the list (That’s what I want), NPC2 will then detect itself. I think I may be misunderstanding some of the logic so any help is appreciated.

This should check if the NPC detected is itself or not. Actor is result of the sight sense perception being updated.

This is the section where it checks if the NPC is already in the list of known characters.
(I think this is the section that is causing me issues but I’m not sure what to replace it with)

Finally, if it is known then don’t add it, if is not known then add it to the list.
UE5DetectionIssue3

i think arrays have a function called “Add Unique”

you could try using that instead of add

but, i’m kinda confused what the problem exactly is. Are you saying you don’t want duplicates and you don’t want self to be added to the array?

Resolved because I realised that the ‘Get all actors of class’ was getting the wrong actor. Here is the update BP:

1 Like