System.InvalidOperationException: Unable to create a SharedStatic for this key

Hey there, happy new year! :partying_face: :upside_down_face:

I currently see crashes when starting my game, which lead to a Unity crash when stopping and then starting the game again:

InvalidOperationException: System.InvalidOperationException: Unable to create a SharedStatic for this key. This is most likely due to the size of the struct inside of the SharedStatic having changed or the same key being reused for differently sized values. To fix this the editor needs to be restarted.

I tried to put all information in these videos:

SharedStatic_1: all package dependencies, how it happens, etc. (Murphy’s Law: at the end of the video, I try to restart the game multiple times, and it doesn’t crash :joy: … usually it crashes with the 2nd start)

SharedStatic_2_UnityCrash: Unity crashes (usually with the 2nd start of the game, when the InvalidOperationException has already happened once)

SharedStatic_Errors.txt: all errors + the Unity crash log

Any info missing?

What can I do to fix this? :slight_smile:

Thanks in advance,


Does this happen every time, or only after you have e.g. changed some package manager dependencies or similar? The error message says that it can be resolved by restarting the editor. Does it happen repeatedly even after restarting the editor?

Hey Aron,

thx for the quick response :slight_smile:

It happens every time I start the game… the crash then ‘usually’ happens on the 2nd start.

I noticed some other errors since A* version 4.3.59 or so, which lead to crashes after playing the game for a while… it always included some Burst compiler error messages.

Since 4.3.61, it behaves like I described above.

I tried out to use exactly the dependencies A* needs, but that didn’t make things better :slight_smile:
So currently I am sticking with what Unity suggests as the most up-to-date versions.

Hmm… Which version of Unity are you using?

Currently it’s Unity 2022.2.1f1 … I try to stay up to date with the latest version, since I am still far from a releasable game, and can afford some errors here and there :rofl:

Hmm. I’m using 2022.2.0b16 so that should be very close to what you are using.
My package only uses a shared static in a single place, and that’s a global static variable in DrawingData.cs. The value is also a single float which always has a fixed size.
This seems like a unity bug to me.

Then I will go with A* 4.3.58 for the moment, cause it doesn’t crash Unity… will check the current A* version out with the upcoming Unity versions, and give you feedback then :slight_smile:

I just upgraded from Unity 2021 to 2022 and this exact same thing is happening to me. The first time I run it I see the errors mentioned, then next time I run it, it crashes Unity.

Unity Version: 2022.2.7f1
A*: 4.3.61

I’ve downgraded to version 4.3.58 which does not crash.


@Jeremy_Frederick Try to restart the Unity editor. It’s a burst limitation.

The Unity editor restarts itself when it crashes, lol. I did this about 6 times before I found this thread and rolled back. I can try again to upgrade to the latest version, but I’m not sure restarting the editor is going to solve it.

interesting information

I wanted to observe it a little bit longer but… with the newest Unity 2022.2.x versions, 4.3.61 “seems” to be running.

I still had some crashes during runtime, not sure which 2022.2.x version. Not sure if it is related … but up until now, the only crashes that “bad” were related to A* (no complains! no offense! :slight_smile: I guess it’s just related to Burst not having much of a stacktrace, or debug/log info, which makes it hard to find errors and their causes … and Unity still developing that stuff)

Still observing :slight_smile: