Hello everyone!
We’ve been working hard on polishing the visuals for a number of Towns in our game (Unity 2D / URP), but a recent update from 2020 LTS to 2021.3 LTS has led to a strange prefab size bloating issue that we haven’t been able to find any solutions or hints for! I posted a similar issue on the SPINE (Esoteric Software) forums thinking it was initially an issue with SPINE (third-party animation software), however after more playtesting, experimenting in prefab editing mode, and more, I think it may have to do with Unity (which then has its effect on SPINE)… and so here I am!
Our game has a complex prefab system for managing towns and other environments—each town has a number of NPCs, each NPC being its own prefab variant (of a baseline NPC) that has most of its settings saved to the prefab variant (exceptions being position in the town, etc., which are saved in the town prefab).
When saving an existing Town prefab, the file size of the prefab jumps 30-50x, from pre-update sizes of around 1-5 mb to 50-90 mb now (in one specific case, 30 mb to 600 mb…;w;). I wasn’t sure what the problem was and didn’t know why 1,500,000-10,000,000 lines were being added to the .prefab file when checking the diff for prefabs on GitHub
I’m finding that a prefab’s data’s triangle, position, color, indices etc data are all being saved into the parent prefab (town), and this seems to be the cause of the prefab file size bloat. Within the Town prefab, I’m seeing millions of lines (with the guid
corresponding to a prefab) like this:
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1388]
value: 463
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1389]
value: 462
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1390]
value: 460
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1391]
value: 461
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1392]
value: 459
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1393]
value: 461
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1394]
value: 460
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1395]
value: 458
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1396]
value: 459
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1397]
value: 460
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1398]
value: 442
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1399]
value: 459
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1400]
value: 458
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1401]
value: 444
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1402]
value: 442
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1403]
value: 458
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1404]
value: 443
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1405]
value: 454
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1406]
value: 457
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1407]
value: 455
objectReference: {fileID: 0}
- target: {fileID: 993508108996568647, guid: 59eecd1c5cc9e44bd99528cfa1581e21,
type: 3}
propertyPath: m_Triangles.Array.data[1408]
value: 457
objectReference: {fileID: 0}
I noticed that this is only bloats the overarching prefab’s size when smaller prefabs (in this case, visuals - trees) are added. Each tree prefab is only 5 kb, yet adding one and saving increases the overall prefab’s size by 1-2 MB.
I’m not sure how reproduction works for this, but it definitely began happening after the update to 2021.3 LTS. Here are some more notes:
- We’re using URP.
- All the visual prefabs (the 5 kb ones that bloat the parent by 1-2 MB) are static and contain two or more instances of URP’s
Light2D
to work with the 2D lighting system we have with. - Deleting the visual prefab from the parent prefab reduces the size by 1-2 MB.
- All visual prefabs are marked as static.
- The only overridden details for a visual prefab are the in-world position and the sorting layer / order in layer for the Sprite Renderer.
If there’s any other information that I should supply to help make this easier to understand/resolve, please let me know! If this can be resolved, we’ll be able to speed up prefab saving times from the current 1-3 minutes to the original 10-25 seconds…!!