shadowmage45 / TexturesUnlimited

KSP Shader, Texture, and Modeling Utilities
GNU General Public License v3.0
29 stars 17 forks source link

Tags not loaded properly from asset-bundle models. #46

Open shadowmage45 opened 6 years ago

shadowmage45 commented 6 years ago

Debug output from an asset-bundle based model, that should have the 'Airlock' tag on the 'Airlock' transform.

[LOG 17:29:20.893] Transform: GameObject 1(Clone) Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Hab3x Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Cube Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Cube.001 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Cube.002 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Cube.003 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Cube.004 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Cube.005 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: node_collider Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: node_collider2 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.001 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.002 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.003 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.004 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.005 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.006 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.007 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.008 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.009 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.010 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Plane.011 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.001 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.002 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.003 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.004 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.005 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.006 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.007 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.008 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.009 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.010 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.011 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.012 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.013 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.014 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.015 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.016 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.017 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.018 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.019 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.020 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.021 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.022 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.023 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Sphere.024 Tag: Untagged Layer: 0
[LOG 17:29:20.894] Transform: Airlock Tag: SmartWater Layer: 21
shadowmage45 commented 6 years ago

Apparently this is a known and long-standing issue with Unity and Asset Bundles (not specifically caused by KSP or TexturesUnlimited) --

https://answers.unity.com/questions/23862/tag-on-a-gameobject-which-is-loaded-as-an-assetbun.html

https://forum.unity.com/threads/my-tags-are-getting-changed-when-its-loaded-from-asset-bundle.466801/

https://forum.unity.com/threads/tags-and-assetbundles.132984/

It has been a problem since at least 2012, with no sign of resolution coming from the Unity devs.


Okay, so the solution is to ensure that your tag list in your Unity Editor exactly matches what is expected by KSP. Any mis-match in the ordering will result in the tags on the objects loaded from the asset-bundle being incorrect.

This is how you need to setup your tags in the Unity Editor in order to have them saved properly into the AssetBundles:

[LOG 16:47:40.526] Load(Model): /tagtest [LOG 16:47:40.531] Debug Output for Model: TagTest(Clone) [LOG 16:47:40.531] Transform: TagTest(Clone) Tag: Untagged Layer: 0 [LOG 16:47:40.531] Transform: Tag-0 Tag: GUIText Layer: 0 [LOG 16:47:40.531] Transform: Tag-1 Tag: SmartWater Layer: 21 [LOG 16:47:40.531] Transform: Tag-2 Tag: KSC Layer: 21 [LOG 16:47:40.531] Transform: Tag-3 Tag: LaunchPad Layer: 0 [LOG 16:47:40.531] Transform: Tag-4 Tag: Kerbin Layer: 0 [LOG 16:47:40.531] Transform: Tag-5 Tag: Mun Layer: 0 [LOG 16:47:40.532] Transform: Tag-6 Tag: Runway Layer: 0 [LOG 16:47:40.532] Transform: Tag-7 Tag: Ladder Layer: 0 [LOG 16:47:40.532] Transform: Tag-8 Tag: Airlock Layer: 0 [LOG 16:47:40.532] Transform: Tag-9 Tag: krakensbane Layer: 0 [LOG 16:47:40.532] Transform: Tag-10 Tag: Icon_Hidden Layer: 0 [LOG 16:47:40.532] Transform: Tag-11 Tag: Icon_Only Layer: 0 [LOG 16:47:40.532] Transform: Tag-12 Tag: NoAttach Layer: 0

[Click and drag to move]

Which looks like this in the editor (click on the 'Add Tag' button, and make sure your list matches this exactly) :

With the above setup completed in your editor install, make sure to fix the tags on your models (they likely were changed when you updated the values in the tag manager), recompile and/or re-export your .smf models (recreate the prefab, and re-build the asset-bundles).

After the tags have been fixed in your editor install, and your asset-bundle models rebuilt, they should then load fine in KSP. (at least my test model loads properly with the above changes having been made, and the asset-bundle for it rebuilt)