Key already exists exception when enter play mode options is on in 1.5.2
See original GitHub issueDescription
A blank unity project with enter play mode options enabled and domain reload off, throws an exception for every network behavior in the project.
The stack-trace highlights even built in network behaviors like networkanimator or networktransform.
ArgumentException: An item with the same key has already been added. Key: 1665640498
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <eef08f56e2e042f1b3027eca477293d9>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <eef08f56e2e042f1b3027eca477293d9>:0)
Unity.Netcode.Components.NetworkAnimator.InitializeRPCS_NetworkAnimator () <0x26f88a73b30 + 0x000ca> in <b476fa4747044164bbf4bd8f8f4d4d2e>:0
A clear and concise description of what the bug is.
Reproduce Steps
- Create a blank unity project in 2022.3.5f1 (URP core)
- Install netcode for game objects version 1.5.2
- Install parallel sync via github link https://github.com/VeriorPies/ParrelSync.git?path=/ParrelSync
- Go to project settings and enable “Enter Play Mode Options”, ensure that “Reload Domain” is off.
- Enter play mode once, then exit.
- Enter play mode again and 2 exceptions should appear. One for NetworkTransform and one for NetworkAnimator.
Actual Outcome
No error
Expected Outcome
One exception for each networkbehavior in the project.
Screenshots
Environment
- OS: Windows 10
- Unity Version: 2022.3.5f1
- Netcode Version: 1.5.2
Additional Context
Error does not appear if the netcode version is downgraded to 1.4.0, or 1.5.1
Issue Analytics
- State:
- Created 2 months ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Configurable Enter Play Mode
We profiled and analyzed Enter Play Mode to understand where the time is spent. As a result, we would like to offer options...
Read more >Issues · Unity-Technologies/com.unity.netcode.gameobjects
New "Writing past the end of the buffer" issue in 1.5.1/1.5.2 (worked in 1.4.0) ... Key already exists exception when enter play mode...
Read more >ArgumentException: An element with the same key already ...
You are trying to add an existing key to a Dictionary . The first error in the Awake function from the ManagerChat script...
Read more >Manual: Configurable Enter Play Mode
To configure the Enter Play Mode settings, go to Edit > Project Settings > Editor and enable Enter Play Mode Options. When you...
Read more >Why do I keep getting an exception about "an element with ...
In the innermost loop of Start() , you're trying to add objectPool to the poolDictionary using pool.tag as the key.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I see where we could avoid this issue. Since the domain is not getting reloaded the RPC dictionary is not being cleared on the codegen/ILPP side of things. This does seem to be a potential regression bug and will investigate the more recent updates to the RPC table generation.
I understand that, but it has worked for all previous versions of NGO, why would it stop working with this version?
Also even though the error is there, the game works perfectly fine, RPCs work etc. Basically the error doesn’t stop the code from working, so it seems like an issue that could be handled. Even if there might be special cases where it would not work.
Also enter play mode is such an improvement to workflow that if you need to enable domain reload to play test, it’s almost a deal-breaker by itself.
It should at least be investigated to see if there are any workarounds.