#[Netcode] Is there a way to tell how many players (if any) are currently connected to the server?
1 messages · Page 1 of 1 (latest)
I assume the way to do it is probably something like this:
private EntityQuery _connectionQuery;
protected override void OnStartRunning()
{
_connectionQuery = GetEntityQuery(ComponentType.ReadOnly<NetworkStreamInGame>());
}
protected override unsafe void OnUpdate()
{
NativeArray<Entity> activeConnections = _connectionQuery.ToEntityArray(Allocator.Temp);
if (activeConnections.Length < 1)
{
//Exit early
return;
}
//Send RPC here
}
(this is Entities 0.51 code, in case it looks funny)