+2
Fixed

ArgumentException: An element with the same key already exists in the dictionary. for 1.2.3 scene variables

GhostAegis 3 years ago updated by BearHugMark 2 years ago 15

So I just updated my project to Bolt 1.2.3. However, I'm suddenly getting a huge cascade of errors throughout the project. Most of this seems to be related to scene variables.

Multiple scene variables across multiple scripts are throwing the error:

ArgumentException: An element with the same key already exists in the dictionary.

whenever I try to define them via macro at runtime. They then fail to define, and then all of the scripts that depend on them blow up. Not all of the scene variables are doing this though, and I can find no common thread between those that are causing the problem.

I did not have this issue on 1.2.2, although I was getting the errors with the Scene variables singleton whenever I'd load a new scene, which is what prompted me to update.

I'm happy to investigate this further, but frankly I'd need some direction to do so. The whole thing is blowing up on me and I have no idea where to look first.

Also, I don't know if it's related, but I also get the error:

Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)

when loading a scene where the ArgumentException occurs.


Oh, and there's a random gameObject type object variable that I CANNOT get to save on one of my prefabs all of the sudden. It keeps resetting to type Null every time I hit play.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
Pending Review

Hi GhostAegis!

Sorry you're having this issue. Issue #2 seems to be just a consequence of #1, and #3 is not actually a bug (see this post).

About issue #1: the error happens in Play mode only, when the Set Scene Variable unit gets called? 

Sorry, wasn't clear about issue #3: It resets to type null even though I have a value stored in it, thus also erasing the value. It's like it doesn't recognize that I stored a gameobject value in it all of the sudden. The exact same variable and corresponding macro worked fine before I updated.


As far as the bigger issue:

The error is definitely only in Play mode. It SEEMS to be only when set scene variable is called, but a number of the errors in the console don't appear to link back to a specific macro (clicking on them doesn't highlight a corresponding gameObject) so I can't be sure.

Also, I just disabled most of the gameobjects with dependent scripts so that my console would stop scrolling infinitely, and noticed this error gets triggered when I run any macro that reloads one of the scenes with the problem:

InvalidOperationException: Scene '' is invalid and cannot be used in singleton operations.

Hi GhostAegis,

I haven't been able to reproduce the issue. Can you create a small test scene in which it happens?

Here's my setup. One scene with a single flow machine using a macro as its source. The graph of the macro is:

Whenever I press play, the scene variable is set properly without error. And when I press space to reload the scene, it reloads without any error either.

Thanks for looking into it. So I it doesn't seem to happen when I test this in a standalone scene. I recreated what you did, I recreated a lighter version of the code in my problem scenes, and got nothing. It's only in happening with the scenes that existed prior to updating to 1.2.3.

Also, I'm noticing a specific sequence of events as I'm playing further with this.

When I reload a scene, it's okay. No errors. But when I move from one scene to another, on entering the new scene I get the "ArgumentException: same key" error and the Some objects not cleaned up" error. When I leave that scene (and it can be any of a number of scenes, so long as it has scene variables), then I get the InvalidOperationException: Scene "" is invalid singleton error.

Interesting thing I just noticed as well: the first two errors can be triggered by exiting play mode, in addition to loading another scene. They appear on my console as I switch back to editing.

The InvalidOperationException can be triggered when I then leave a scene that got the first two errors, but in both play AND in edit. Even selecting another scene from the project manager and loading it in edit mode causes the problem, but ONLY if I've just left play mode and gotten the first two errors already. Subsequent scene loads in edit mode do not trigger errors.

Could this have something to do with the fact that this stuff existed before the scene variable bug was patched?

+1

Same error for me when I'm loading scene :

ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[UnityEngine.SceneManagement.Scene,Bolt.SceneVariables].Add (Scene key, Bolt.SceneVariables value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
Ludiq.SceneSingleton`1[Bolt.SceneVariables].Instantiate (Scene scene) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Unity/SceneSingleton.cs:120)
Ludiq.SceneSingleton`1[Bolt.SceneVariables].InstanceIn (Scene scene) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Unity/SceneSingleton.cs:74)
Bolt.SceneVariables.Instance (Scene scene)
Bolt.VariablesWidget+Tab.Scene () (at C:/Users/lazlo/Projects/Ludiq/Bolt.Flow/Editor/Variables/VariablesWidget.cs:339)
Bolt.VariablesWidget.Update () (at C:/Users/lazlo/Projects/Ludiq/Bolt.Flow/Editor/Variables/VariablesWidget.cs:37)
Bolt.VariablesWindow.UpdateWidget () (at C:/Users/lazlo/Projects/Ludiq/Bolt.Flow/Editor/Variables/VariablesWindow.cs:86)
Ludiq.EditorApplicationUtility+<>c__DisplayClass49_0.<SafeCallbackFunction>b__0 () (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Editor/Utilities/EditorApplicationUtility.cs:86)
UnityEditor.EditorApplication.Internal_CallHierarchyWindowHasChanged () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:153)


Fixed in Alpha

Thanks for the log. I'll attempt a fix for v.1.2.4, I suspect Unity might be destroying/recreating the scene singleton object when Bolt asks it to switch scene, which messes up with my pseudo-singleton code.

Great! I hope project will be totally clean of false warnings and errors with 1.2.4 

Thanks for getting something moving on this! Hopefully no more errors with scene variables after this update, fingers crossed

+1

Hey there! I encountered the same problem trying to use the "Platformer" tutorial.

From what i understand here, it seems like the problem is with me using the given levels from the import? (that are a bit corrupted in my editor - unity 2017.4.1f).


I did some testings, and it seems like moving with a scene containing the "Scene Variables" (even if it is a new scene that i just created) to another scene (even using my own script and not through bolt, and even if that scene DOES NOT contain any bolt related objects) will cause the problem.

It seems like I CANT seem to create a scenario of me using bolt and NOT having that problem.


Here is a small and simple recreation. 2 Scenes, each with an emptyt bolt macro flow on an empty object. I added an Object variable to the first scenes flow, and once i move (using an outside code) to another scene - the error happens.

Download link (for the next 30 days) to the source code for that (again, using unity 2017.4.1f) :

https://ufile.io/8ltdb


Would love to know an ETA for a fix on this, because without it I can't start using it for my game :(

I can confirm with Kingblade that I too get the error in the platformer tutorial. I noticed the error after the player collides with the objective and therefore gets taken to Scene2.  

I can also confirm that the platformer project is curropted in some way as "Sorting Layer" was not set on any of the game objects.

I am also stuck with this error but I'm not sure how. In mine; it will throw up this error Log here

it will happen either when i load the scene from another scene(instantly),
or from inside the scene itself(it will run just fine for about 5 seconds (until "Documentation (mscorlib)..."finishes loading.

What i think causes it was me downloading some of the macro's some of you posted here.
I downloaded JasonJonesLASM's Enum Generator & Unit Tools : Flow Control

This is all the info i got. if that helps.

Hi William,

Are you using Bolt v.1.3?

I actually just got done updating to 1.3 after reading through some other stuff. It manage to fix the problem. Sorry about that.

Hi guys, I still get this error and I'm running v1.3.0 - my iOS build of the game has the error at/near startup. I've even removed any scene changes and it still happens.


Any ideas at all?