Getting number of npc's in a sphere

Hi,

I’m trying to count the amount of npc’s around the player character in a sphere to send to FMOD. I’m using SphereTraceForObjects to trace for ObjectTypes. This works but now I need the result to be the amount of npc’s. How do I go about it now?

Also what would be the best way to trigger the spheretrace?

Thanks in advance!

For Each loop, and IF object is class you need add its reference to another array, then take size of resulting array. And dont forget to clear array every time you start counting.

I assume that you want to do something with those npc’s later, if not just increase some integer instead of gathering references.

Not sure what you want do, but you may think about solving whole code from another side.
From game mode or player controller fire dispatcher every 0.2 seconds or so. All npcs should assign some event to that dispatcher, and when it is fired npc should calculate distance to player and report result (update some variables in player blueprint).

So you can have logic for npcs in range either in player blueprint or in npc blueprint, really depends if player does something with them or they need to be aware of distance.