fix: defer ObjectSceneChanged events to occur after client has finished synchronizing#2502
Conversation
|
|
||
| var deferredObjectsMovedEvent = new NetworkSceneManager.DeferredObjectsMovedEvent() | ||
| { | ||
| ObjectsMigratedTable = new Dictionary<int, List<ulong>>() |
There was a problem hiding this comment.
Since these can be created dynamically at any time here, I worry about the GC pressure that might be added if a lot of these come in rapidly. Could this be changed from Dictionary<int, List<ulong>> to NativeHashMap<int, NativeList<ulong>>? Allocating with Allocator.Persistent would be required but that's still better than GC allocation... especially given the potential number of calls to new List<ulong>() below.
There was a problem hiding this comment.
This will only happen under the following conditions:
- A client is going through the initial synchronization process after the client has connected and the connection has been approved.
- While the client is processing the synchronization message (i.e. loading scenes, instantiating NetworkObjects, etc) the client receives and processes a ObjectSceneChanged event.
So, regarding memory allocation it is basically during a period of time where GC will always be at its "highest peak". Once a client is synchronized this section of code will never get invoked...so in reality the DeferredObjectsMovedEvent structure wont be allocated at any time... only during client synchronization and only if the client receives any ObjectSceneChanged events while processing the synchronization message...which each ObjectSceneChanged event can contain (n) number of scene handles with associated NetworkObject identifiers (i.e. the server batches NetworkObject scene changes together for each frame... so if a user migrates 100 NetworkObjects into a different scene all at once there will be 1 ObjectSceneChanged event that contains the target scene handle and all of the NetworkObject identifiers to migrate into the target scene...which under this scenario would allocate 1 DeferredObjectsMovedEvent structure to defer the processing of that event to after the client has finished synchronizing).
Fixes the issue where a client could receive a SceneEventType.ObjectSceneChanged message while in the middle of synchronization which could cause an exception to be thrown due to a NetworkObject not yet being instantiated and spawned.
MTT-6188
Changelog
Testing and Documentation