Download

performance considerations about presence detecction (or distances calculation)

Hi,

I’m not sure about which is the best way to manage distances between a lot of characters. Is better compute distances each tick (square distances) or check if one char is close to another using a sphere volume with the overlap event??

In my case I have about 30 ~ 40 characters and there are two different teams. I don’t need to check distances between mates but I have to trigger different behaviours when a character of the opposite team is near. The Pawn sensing component is discarted because characters don’t really need to see each other to trigger their actions.

Which option is better??

thanks

I had to do something like that for a server once which had to deal with quite a big world and lots of different enemies that all had to be able to attack each other. Now keep in mind this was not UE4 and maybe UE4 has something built in that makes this redundant:

(In your case I’m not sure if this approach would help your performance or harm it, but maybe it’ll be helpfull nonetheless. It really depends on the amount of enemies.)

What I did was seperating the world into “cells”. In UE4 it would work like this to get the current cell to the position: FVector2D(int(Pos.X/CellSize), int(Pos.Y/CellSize)); I wrote this in Squirrel which has tables where I would then add this as key and the enemy as a value (I think in UE4 you would use TMap for that). If you update this for all of your enemies regularly, instead of having to check the distance to every single enemy from every single enemy, you would only need to check a few adjacent cells (You could also let it iterate the adjacent cells until it finds a cell that is not empty, which I used to find the nearest waypoint.) Now, I’m not sure how efficient the collision-detection is, maybe that would be a better approach since this will only really have a positive impact on performance when there’s many enemies present. I had to deal with a few hundreds of them at once that all had to be able to attack each other.

Good luck in any case. Interested to see some replies on this topic myself :slight_smile:

UE4 collisions work somewhat like what you described, Hammel.

I would recommend checking in tick manuallly for small amount of entities (<10-20).

For bigger amounts of entities (especially 100+) I would highly recommend using collision-spheres. They have a reason why they exist :stuck_out_tongue:

Hi!

Thanks dudes! I will try with collision spheres. If they works as Hammel described and my entities will be more than 20, it’s probably the best choice.

Bye!