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:

https://drive.google.com/drive/folders/1ttffx0Z-e0JEeGt2TII5voLkRT_A7qzP?usp=sharing

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,
Denzi

Hi

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.

Hi

@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: