Hello,
I have a numeric lobby field that stores language preferences as an integer from an enum. Everything works fine to filter and query by one language. However, now I thought that it would like nice to be able to store certain lobby data as a Flags enum and then run queries using bitwise operations. Right now, numeric lobby fields do not seem to support this. Adding support for bitwise checks on numeric fields that represent Flags enums would let us store and filter complex sets of options more easily.
Is there already a way to do this that I am not aware of? If not I think this would be a great feature to have.
Thank you for the question!
First, to recap the current functionality, Lobby queries (which include those in a QuickJoin) are expressed as an AND
combination of zero or more filter, each of which has:
field
op
(operator) which can beEQ
,LT
,GT
, etc.value
(always ofstring
string type)
The value
is always expressed as a string
. There is a CONTAINS
operator but it is limited to substring matching in the Name
field (which is always indexed).
For the case of multi-value matching, it depends on the cardinality of the relation:
- one to many – client has multiple values, lobby has one, client wants lobbies whose value is any of the first set
- many to many – client has multiple values, lobby has multiple values, clients wants to join a lobby with some set operation (equality, some intersection, etc.)
Because the filters
are always AND
, it’s not possible to expand multiple values into an OR
. And because value
cannot be an array, it can’t be done within a single filter either.
The original question is on bitwise operators and bitfield values, a compact solution to this. However I believe there might be greater value in supporting generalized set operations for any value type.
Some sketches (not actual API):
new ONEOF
operator
"filters": [
{
"field": "lang",
"op": "ONEOF",
"value": ["en", "es", "fr"]
}
]
new filtersOp
option (AND
/OR
)
"filtersOp": "OR",
"filters": [
{
"field": "lang",
"op": "EQ",
"value": "en"
},
{
"field": "lang",
"op": "EQ",
"value": "es"
},
{
"field": "lang",
"op": "EQ",
"value": "fr"
}
]
The second one being even more general as the field
can change between different filters.
Though it isn’t directly a bitwise filter, would functionality like this cover your use case of filtering for language choices?
Hey, thanks for the reply. Yes, this would cover my case of filtering language choices, and I think it’s an even more straightforward approach than using flags enums. Does this mean you’re considering adding this feature to lobbies in the future?
Great, thanks for confirming.
I have submitted this thread to our internal board for consideration. If it makes the cut, it will appear in the Roadmap section for UGS: https://unity.com/roadmap/unity-gaming-services/multiplayer
Don’t hesitate to submit other ideas through this same page.
We love hearing from customers.