EsotericSoftware / spine-runtimes

2D skeletal animation runtimes for Spine.
http://esotericsoftware.com/
Other
4.41k stars 2.91k forks source link

[unity] UPM package Index out of bounds exception in editor code #2095

Closed HaraldCsaszar closed 2 years ago

HaraldCsaszar commented 2 years ago

Originally reported on the following issue ticket by @ianmccleary: "[unity] Unity scoped package registry #1676" https://github.com/EsotericSoftware/spine-runtimes/issues/1676#issuecomment-1151741056_ Split off to this separate issue ticket.

Original text below: Hello, I'm importing the spine runtimes through UPM in Unity 2020 LTS. It often runs into an "Index out of bounds of the array" error at this line (176)

https://github.com/EsotericSoftware/spine-runtimes/blob/0c286734a7274b63ac07c9f494a2260b6e188819/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs#L175-L176

I believe this happens because the FindAssets call is not properly looking in the Packages folder. I fixed it locally by adding a folder arg to FindAssets in line 175 and 179:

var folders = new string[] { "Packages", "Assets" };
// ...
string[] assets = AssetDatabase.FindAssets("t:script SpineEditorUtilities", folders);

This forces Unity to search in both the Packages and Assets folder. However, I have not tested if this works if the package is imported in the traditional way and lives in the Asset folder. I apologize, as I don't have the bandwidth to properly test this fix myself. Could this be looked into further?

murshex commented 2 years ago

I still have this error for some reason

murshex commented 2 years ago

I am going to try: string[] assets = AssetDatabase.FindAssets("SpineEditorUtilities t:script a:all");

murshex commented 2 years ago

SpineEditorUtilities.ConfirmInitialization is called on a worker thread. This is the problem.

murshex commented 2 years ago

This issue is being caused by RenderStaticPreview being overridden in UnityEditor.Editor for the custom inspectors. I'll stop commenting and submit a pull request after I fix it.