Stale NetworkList event sent to client when its containing object is re-shown.
See original GitHub issueDescription
I have a network object observed by a client containing a network list of structs. On direction by the client a timer is started on the server to remove the entries from the list from the bottom at half a second intervals. At any point the client can choose to deselect the object and the server hides the object from the client and continues to remove entries from the list until all are removed, all is good at this point.
The problem is, the next time the object is shown to the client a pending network list event message is also sent to the client to remove an entry from the network list and because the list is empty an exception is thrown.
Reproduce Steps
- Spawn object on client and populate network list
- Start timer to remove list entries one at a time
- Server hides object from client
- All entries in list removed, timer stops
- Server shows object to client
- NetworkList exception message logged on client
Actual Outcome
“Exception: Shouldn’t be here, index is higher than list length”
Expected Outcome
No network list event message is sent to client.
Environment
- OS: macOS Big Sur
- Unity Version: [e.g. 2020.3]
- Netcode Version: 1.1.0
Additional Context
This happens consistently in my main project, I wasn’t able to reproduce it in a test project but it was only a simple test.
Both list.RemoveAt and list.Remove are producing the same error:
Exception: Shouldn't be here, index is higher than list length Unity.Netcode.NetworkList1[T].ReadDelta (Unity.Netcode.FastBufferReader reader, System.Boolean keepDirtyDelta) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/NetworkVariable/Collections/NetworkList.cs:365) Unity.Netcode.NetworkVariableDeltaMessage.Handle (Unity.Netcode.NetworkContext& context) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs:200) Unity.Netcode.MessagingSystem.ReceiveMessage[T] (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.MessagingSystem system) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:457) Unity.Netcode.MessagingSystem.HandleMessage (Unity.Netcode.MessageHeader& header, Unity.Netcode.FastBufferReader reader, System.UInt64 senderId, System.Single timestamp, System.Int32 serializedHeaderSize) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:387) UnityEngine.Debug:LogException(Exception) Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single, Int32) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:391) Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Messaging/MessagingSystem.cs:407) Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1581) Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkManager.cs:1513) Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:185) Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.1.0/Runtime/Core/NetworkUpdateLoop.cs:208)
Issue Analytics
- State:
- Created 10 months ago
- Comments:21 (10 by maintainers)
Top GitHub Comments
Hi,
I managed to repro and explain the issue. Working on a fix. WIP at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/2328
The issue is fixed in my main project. In my test project where it toggles in Update I’m getting this warning:
“Object was shown and hidden from the same client in the same Network frame. As a result, the client will not receive a NetworkSpawn”
What would a Network frame be?