Cammin / LDtkToUnity

Unity importer for the LDtk level editor
https://cammin.github.io/LDtkToUnity
MIT License
388 stars 39 forks source link

Importer logs warnings when reimporting a LDtk asset that's part of a prefab #27

Closed lexusinator closed 3 years ago

lexusinator commented 3 years ago

Summary

If your LDtk asset is part of a prefab, the importer will log warnings that names are not unique and that subsequent imports may not properly re-link.

Steps to reproduce

1. Add a LDtk asset under an empty parent object, make that parent object a prefab.

image

2. Reimport the LDtk asset.

image Warnings are logged to the console. image

Stuff that might help

Warnings logged to the console:

Creating missing Tilemap component for TilemapCollider2D in Missing Prefab (Dummy).

Creating missing Tilemap component for TilemapCollider2D in Missing Prefab (Dummy).

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy), Type:GameObject'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy), Type:GameObject'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy)/Transform, Type:Transform'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy)/Tilemap, Type:Tilemap'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy), Type:GameObject'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy)/Transform, Type:Transform'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

Identifier uniqueness violation: 'Name:6705443923001353219/Gunsmith Dungeon (Missing Prefab)/Missing Prefab (Dummy)/Tilemap, Type:Tilemap'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.
Cammin commented 3 years ago

Again, awesome repro steps. 🙂

I believe I remember trying this one time, but maybe I didn't reimport while doing this.

But this is generally a limitation of the import process; if any GameObjects are siblings in their import hierarchy and have the exact same name, then the import system can't correlate identifiers, which affects how unity might track scene/prefab overrides for which object to maintain the overrides for in the occurence of a reimport. (This also happens if multiple of the same component are in a gameobject, like two box colliders for example)

The problem is inconsequential as long as no scene/prefab overrides are used for those specific objects in question, but I can understand if the logs are bugging you. 😅

I'll check this out and see what I can do, but I can't guarantee if this is truly fixable 😅

I think I could create a documentation topic about this, in case this might ever happen to anyone. I can predict that people might use multiple components in an entity prefab, so explaining that detail would be helpful 🙂

lexusinator commented 3 years ago

Ahh, I see! Weird how that works. Actually I wanted to use overrides on that object, but I guess I won't. 😅 Yeah a note in the documentation is a good idea!

Cammin commented 3 years ago

The import process does not like duplicate-named components or sibling GameObjects

Cammin commented 3 years ago

Testing and I found an extra problem related to this. I've done the repro steps, and then further tried dragging a prefab using the .ldtk prefab into a scene. It results in this which is definitely not expected. image
Inside the prefab content, it's working correctly. However, It's not turning out correctly in the scene.

So I'm going to see if I can find a solution to this import pipeline problem 🙂

I think it might be some sort of problem due to how gameobjects are created during the import process. I'm curious how Unity specifically does theirs potentially differently (FBX for example) to create their gameobjects into their import result.

Cammin commented 3 years ago

I think I found my solution. The error was happening even before the import process was happening. So I think the problems were coming because prefabs were being imported before the LDtk projects were. By changing the LDtk project's importer's importQueuePriority, it now imports before prefabs do, and that fixed it, no more log warnings 😄

So what I believe was happening is that because the LDtk project was placed in a prefab, the LDtk project now becomes a dependency of the prefab, so that means that reimporting the LDtk project also means that the prefab gets reimported. And so because the prefab was being reimported first, It didn't know how to exactly deal with the old LDtk project (because the LDtk project still needed to be reimported next).

So consider this fixed. This will come in the next update. Will close this issue when the update comes 🙂

lexusinator commented 3 years ago

Oh wow, awesome that you found a fix for that, that's a big one! 😊

Cammin commented 3 years ago

The 2.1.4 update is now up which has a few bug fixes and better text contrast behind certain colors 👍 Feel free to post more issues if you have any 🙂