When passing a classname filter to nearestObjects / nearObjects, many results will be omitted even if they match the filter. {F22413}
Description
Details
- Legacy ID
- 2666311346
- Severity
- None
- Resolution
- Open
- Reproducibility
- Always
- Category
- Scripting
Open attached repro mission. Preview and read the hint displaying the output of two subsequent nearestObjects calls. While the two results should be equal, the filtered one is in fact empty.
This issue was not present in 1.00
Event Timeline
The thing is that pre-placed Land_HBarrier_1_F are not actually vehicles but just "models", you cannot do anything them with (apart from setVectorUp). Before last patch they were vehicles and had classnames, last patch changed all these HBarriers into simple models like it was on Stratis from release.
You are right, but there is a problem with your test:
1 meter is not enough to detect a Land_HBarrier_1_F, even if you are standing next to it. The distance between the player (feet), and the center of the H-Barrier, is about 1.3 meters.
Now, on the actual defect... if you manually spawn a Land_HBarrier_1_F, using createVehicle command, it detects it fine. It looks like the issue is only with objects that are part of the map's terrain.
Pre-placed map HBarriers are not vehicles, they are just models, like rocks or trees, they are not actually vehicles in that kind that you create with createVehicle, they simply have same model as their vehicle counterparts. Try to get these HBarriers with [] and then call typeOf on them you will see that they return no class (""), meaning that these are objects with very simple simulation, just models (thats why you can't set their position, attach them, etc.).
@micovery "1 meter is not enough to detect a Land_HBarrier_1_F, even if you are standing next to it. The distance between the player (feet), and the center of the H-Barrier, is about 1.3 meters." The 1m are not relative to the player but to the game logic object and the unfiltered output proves that 1m is enough in this case.
@SaMatra
I also cannot setPos other pre-placed objects which _are_ properly matched by the classname filter.
So if BI thinks this is really necessary for performance sake I would like to ask how I can filter the unfiltered list myself to get all objects sharing a certain p3d file.
For everyone suffering from this issue as well, this is my (ugly) current workaround. Note that the array _nonexisting_classes is only an example and still needs to be extended.
-------------
/**
Will return an array of all objects within area of a given class.
This will also find "pseudo-objects" stripped of their class for performance reasons.
Arguments:
0 center of area
1 classname of objects to find
2 radius of area to search in
*/
_center = _this select 0;
_class = _this select 1;
_radius = _this select 2;
//these are classnames which are stripped from pre-placed map objects for some performance reasons:
_nonexisting_classes = [
["Land_Net_Fence_8m_F", "net_fence_8m_f.p3d"],
["Land_Net_FenceD_8m_F", "net_fenced_8m_f.p3d"]
];
_replacement_name = [_nonexisting_classes, _class] call BIS_fnc_getFromPairs;
_result = [];
if(isNil "_replacement_name") then
{
_result = nearestObjects [_center, [_class], _radius];
}
else
{
{
_name = ([str _x, " "] call BIS_fnc_splitString) select 1; if(_name == _replacement_name) then { _result = _result + [_x]; };
} forEach nearestObjects [_center, [], _radius];
};
_result;
I would like to hear any proposals of better solutions.
use
_result set [count _result, _x]
instead of
_result = _result + [_x]
or you will pay with performance on longer array.