I tried to find more fps optimized replacement for the GetObjectsAtPosition() function and came across this function:
//! finds all entities in a radius proto int SphereQuery(vector origin, float radius, out IEntity visents[], int ents, int fmask);
But no matter what variables I use, I always get 0 from this function.
Here is an example of one of the variations of the code that I use:
private array<Object> objectsInArea = {}; private array<CargoBase> proxyCargosInArea = {}; GetGame().GetObjectsAtPosition(GetPosition(), 50, objectsInArea, proxyCargosInArea); foreach (Object obj: objectsInArea) { PlayerBase player; if(Class.CastTo(player, obj)) Print("PLAYER CURRET FLAGS: " + player.GetFlags().ToString()); } int flagsSum = EntityFlags.VISIBLE | EntityFlags.TOUCHTRIGGERS; Print("FLAGS SUM: " + flagsSum.ToString()); IEntity visents[10]; Print("SphereQuery-1 = " + SphereQuery(GetPosition(), 50, visents, 10, EntityFlags.ACTIVE).ToString()); if(visents[0]) Print("visents[0] = " + visents[0].ToString()); Print("SphereQuery-2 = " + SphereQuery(GetPosition(), 50, visents, 10, EntityFlags.VISIBLE | EntityFlags.TOUCHTRIGGERS).ToString()); if(visents[0]) Print("visents[0] = " + visents[0].ToString()); Print("SphereQuery-3 = " + SphereQuery(GetPosition(), 50, visents, 10, flagsSum).ToString()); if(visents[0]) Print("visents[0] = " + visents[0].ToString()); Print("SphereQuery-4 = " + SphereQuery(GetPosition(), 50, visents, 10, 0).ToString()); if(visents[0]) Print("visents[0] = " + visents[0].ToString()); Print("SphereQuery-5 = " + SphereQuery(GetPosition(), 50, visents, 10, EntityFlags.STATIC).ToString()); if(visents[0]) Print("visents[0] = " + visents[0].ToString());
Here is what I get:
SCRIPT : PLAYER CURRET FLAGS: 9 SCRIPT : FLAGS SUM: 9 SCRIPT : SphereQuery-1 = 0 SCRIPT : SphereQuery-2 = 0 SCRIPT : SphereQuery-3 = 0 SCRIPT : SphereQuery-4 = 0 SCRIPT : SphereQuery-5 = 0
I tried this function in 1.17, 1.18 and 1.19 experimental -> every time result is the same