Spine version downgrade compatibility problem handling

Version related knowledge

First look at the stuff related to the Spine version. One is the software version of Spine, the other is the engineering version of Spine (.spine), the other is the file version exported by Spine (.atlas png bytes/json), and the last is the version of Spine runtime used by Unity. The software is backward compatible with the Spine project, and the others are basically incompatible. The same version is required for normal use. Where runtime is an open source project, here is the git project address

The Spine software version can be selected at startup, as shown in the following figure

A higher version of Spine software can open a lower version of the project file (4.0 software opens a 3.6 project), but note that if you save it after modification, it will cause the project file to be upgraded to a higher version, making it impossible to roll back. Therefore, when performing this operation, it is recommended to back up the lower version project first.

High-version Spine software can export low-version export files, and you can select the version when exporting, but there will be some information loss and compatibility issues.

Spine software cannot import export files of lower versions. Spine export files and SpineRuntime versions are in one-to-one correspondence. If the exported Spine animation files are inconsistent with the Runtime version, incompatibility problems may occur. And SpineRuntime and Unity also have a certain correspondence. The following figure is the corresponding relationship displayed on the official website as of January 24, 2022. If there is any change, you can click to view the information on the official website

Spine runtime version

Supported Unity Versions

spine-unity 4.0.00+

Unity 2017.1-2021.1

spine-unity 3.8

Unity 2017.1-2020.3

spine-unity 3.7

Unity 5.6-2018.4

spine-unity 3.6

Unity 5.6-2018.2

spine-unity 3.5

Unity 5.4-2017.1

spine-unity 3.0

Unity 4.6

Downgrade steps

Operating environment: Unity target version is 2020, spine runtime 3.6, spine project and software are both 4.0

1. Export spine animation files

Open the project, select version 3.6 when exporting the file, and generate the .atlas.txt .png .json file

The generated files are as follows

There is a problem to pay attention to here. The spine version field of the exported file needs to be modified. Although the selected version is 3.6, when exporting, the version field is displayed as "spine": "3.7-from-3.8-from-4.0.58". Change the spine version field to 3.6

before fixing:

{

"skeleton": { "hash": "/iWACBJx9C0", "spine": "3.7-from-3.8-from-4.0.58", "x": -1075.55, "y": -637.13, "width": 2041.4, "height": 1498.37 }

}

After modification:

{

"skeleton": { "hash": "/iWACBJx9C0", "spine": "3.6", "x": -1075.55, "y": -637.13, "width": 2041.4, "height": 1498.37 }

}

2. Generate material and .asset files

Here, if the generated .atlas.txt .png .json file is directly imported into the unity 2020 project, the SkeletonData.asset file cannot be correctly generated. So you need to use a lower version of unity.

So first drag the export file to the unity 2019 project that has been added to the spine 3.6 runtime, and generate the .asset file and material correctly.

3. Import the spine export file and the generated material and .asset files

In unity2019, select the export file and the generated material and .asset file, etc., export the resource to the .unitypackage file, and finally return to the unity 2020 project, and then import the .unitypackage file. The animation can be used normally. (Note that if you drag the file directly here, you will also make an error if you drag it directly to the 2020 project)

Problems caused by downgrading the version

1. Loss of curve information

Use spine 4.0 software to export animations with curve attributes in versions 3.6 and 4.0 respectively

The following is version 4.0, you can see that the "curve" information is exported normally

"zhuzi4": {
        "translate": [
          {
            "time": 0.125,
            "x": -84.08,
            "y": -10.78,
            "curve": [
              0.307, -74.64, 0.477, -67.23, 0.307, -10.78, 0.477, -10.78
            ]
          },
          {
            "time": 0.625,
            "x": -62.73,
            "y": -10.78,
            "curve": [
              1.055, -51.65, 1.457, -43.65, 1.055, -10.78, 1.457, -10.78
            ]
          },
          {
            "time": 1.825,
            "x": -39.13,
            "y": -10.78,
            "curve": [
              1.884, -38.39, 1.942, -37.72, 1.884, -10.78, 1.942, -10.78
            ]
          },
          { "time": 2, "x": -37.15, "y": -10.78 }
        ],
        "scale": [
          { "x": 0.5, "y": 0.5, "curve": "stepped" },
          { "time": 0.125, "x": 0.5, "y": 0.5 },
          { "time": 0.3, "x": 1.04, "y": 1.04, "curve": "stepped" },
          { "time": 1.825, "x": 1.04, "y": 1.04 }
        ]
      }

The following is version 3.6, you can see that all the curve information of translate is lost.

"zhuzi4": {
          "translate": [
            { "time": 0.125, "x": -84.08, "y": -10.78 },
            { "time": 0.625, "x": -62.73, "y": -10.78 },
            { "time": 1.825, "x": -39.13, "y": -10.78 },
            { "time": 2, "x": -37.15, "y": -10.78 }
          ],
          "scale": [
            { "x": 0.5, "y": 0.5, "curve": "stepped", "time": 0.0 },
            { "time": 0.125, "x": 0.5, "y": 0.5 },
            { "time": 0.3, "x": 1.04, "y": 1.04, "curve": "stepped" },
            { "time": 1.825, "x": 1.04, "y": 1.04 }
          ]
        }

I went to the official website to report this problem. The official reply is that some information will be lost when the high version exports the low version file. You can view the post here.

However, after trying, it was found that 3.6 itself supports the curve operation, so you can manually add the curve attribute of the 4.0 export file to the 3.6 export file.

2.Path animation lost

Import animation found that the original path animation is missing. Compare the 3.6 version json exported with the 4.0 version project and the 3.6 version json file exported with the 3.6 version project. The keyword of the path animation in the json file exported in 3.6 is "paths", while the path animation in the json file exported in 4.0 is "path", which makes it unrecognizable when json is parsed. Check the spine runtime related code and find that the logic of json parsing is in SkeletonJson.cs // Path constraint timelines. The code below

The original code is

// Path constraint timelines.
if (map.ContainsKey("paths")) 
{
    foreach (KeyValuePair<String, Object> constraintMap in (Dictionary<String, Object>)map["paths"]) 
    {
        //这里的逻辑无需修改,就不贴了
    }
} 

The modified code is

// Path constraint timelines.
// 3.6版本默认导出的key是paths,4.0降版本之后导出的key是path,为了兼容,同事判断两个key
string[] pathKeys = { "paths", "path" };
string finalKey = null;
for (int i = 0; i < pathKeys.Length; i++)
{
    if (map.ContainsKey(pathKeys[i]))
    {
        finalKey = pathKeys[i];
        break;
    }
}
if (finalKey != null) 
{
    foreach (KeyValuePair<String, Object> constraintMap in (Dictionary<String, Object>)map[finalKey]) 
    {
        //这里的逻辑无需修改,就不贴了
    }
}

After the modification, the path animation can be played normally.

Guess you like

Origin blog.csdn.net/shaobing32/article/details/122689160