Download

Remove single instance of actor from array - how?

Hi

A brief intro to the scenario; I am working on communication between my NPCs. Basically I want that if an NPC spots the player other NPCs within vision range of said NPC will receive notification also. The way I want to do this is by creating an array of all actors to which I want cast an event if the actor is visible by the NPC that spots the player.

My current setup; I am largely following this tutorial series by Asher Einhorn (UE4 Tutorial Series - AI - YouTube) I have created a btservice blueprint. At “Event Receive Activation AI” I “Get all actors of class” and save that to an array. When I do this of course the actor itself gets added to the array and I need to remove it from the array as I will otherwise cast the event to the very npc that spots the player. I tried with the “Remove” node but that doesnt seem to work (it also appears to be supposed to remove ALL instances of a specific actor type - not just this particular instance)

114df3395d4ae962f111c71bbe0a950011668039.jpeg

Also; Is there any way I can call an event in a BTService used by a particular NPC? What I have currently, I can call an event on the NPC itself but that doesnt help me as I have to reach the BTService and call an event there instead - ?

f6ca467cfc16cda02de4bd2f6475fa574e07c1da.jpeg

Any help would be greatly appreciated :slight_smile:

You could try it with “Remove Index”. Find the instance in the array, and remove it with the index.

Hi Kraut :slight_smile:

Thanks. I tried with a “Find” in the array but its supposed to just give you the first instance of that actor in the array and thus not necessarily the correct instance. Is there any way to find a specific instance of an actor in an array? Thanks

You can create a Flag(boolen) in the npc and mark as delete from array. You can then check this flag for each npc.