TSet::ToArray makes heap allocations. Given how frequently RefreshObstructionAndOcclusion is called, if (in_Listeners.Array().FindByPredicate(ListenerIDsMatch) == nullptr) is likely to put undue pressure on memory allocation.
I made a slightly different change at the top of that loop. Would you be willing to merge it?
bool bFoundValid = false;
for (TWeakObjectPtr<UAkComponent> InListener : in_Listeners)
{
if (InListener.IsValid() && InListener->GetAkGameObjectID() == Listener)
{
bFoundValid = true;
break;
}
}
if (!bFoundValid)
{
It.RemoveCurrent();
continue;
}