InvalidOperationException: GetSingleton<Unity.NetCode.NetworkId>() requires that exactly one entity exists that match this query, but there are none. Are you missing a call to RequireForUpdate()? You could also use TryGetSingleton()
Unity.Entities.EntityQueryImpl.GetSingleton[T] () (at ./Library/PackageCache/com.unity.entities@1.2.0-exp.3/Unity.Entities/Iterators/EntityQuery.cs:1485)
Unity.Entities.EntityQuery.GetSingleton[T] () (at ./Library/PackageCache/com.unity.entities@1.2.0-exp.3/Unity.Entities/Iterators/EntityQuery.cs:2785)
Unity.NetCode.GhostUpdateSystem.OnUpdate (Unity.Entities.SystemState& systemState) (at ./Library/PackageCache/com.unity.netcode@1.2.0-exp.3/Runtime/Snapshot/GhostUpdateSystem.cs:1139)
IndexOutOfRangeException: Index 0 is out of range of ‘0’ Length.
Unity.Collections.NativeArray1[T].FailOutOfRangeError (System.Int32 index) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:325) Unity.Collections.NativeArray1[T].CheckElementReadAccess (System.Int32 index) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:166)
Unity.Collections.NativeArray1[T].get_Item (System.Int32 index) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:189) Unity.NetCode.CommandSendSystem2+SendJobData[TCommandDataSerializer,TCommandData].Execute (Unity.Entities.ArchetypeChunk chunk, System.Int32 orderIndex) (at ./Library/PackageCache/com.unity.netcode@1.2.0-exp.3/Runtime/Command/CommandSendSystem.cs:432)
GhostUpdateSystem line 1139
var localNetworkId = SystemAPI.GetSingleton<NetworkId>().Value;
These are no warnings: these are bad and real errors.
The first strange thing is the first error: CommandSendPacket that fail with -3 (NetworkStateMismatch) that suggest the connection was somewhat closed or in strange state.
Indeed when we process the NetworkStreamRequestDisconnect request we disconnect the connection first (that is then in Disconnecting state) and at the beginning of the next frame we dispose the connection entity.
But for the whole frame that connection should still be in a usable state. None touches the NetworkId or something like that.
To which ECB you added the NetworkStreamRequestDisconnect ? Begin frame, end frame, none of these ?
Where the system that does that run ?
Just to understand the timing in order to repro the problem,
Then, in general,… the GhostUpdateSystem only runs if there are connection that has NetworkStreamInGame. So even if you add the NetworkStreamRequestDisconnect it runs and that it is fine.
What I find controversial here is that the system is running (so all the RequireForUpdate condition passes) but there are no connection with NetworkId component… that is really strange.
Are you sure aren’t you doing something else to the entity that has the NetworkStreamConnection component, or in general to the connection (like: calling Disconnect() on the NetworkStreamDriver) ?
The problem was that NetworkStreamInGame wasn’t being removed (line of code was probably removed in the refactor), now that I’m doing that along with the NetworkStreamRequestDisconnect everything is fine.