SuperTiled2Unity icon indicating copy to clipboard operation
SuperTiled2Unity copied to clipboard

Changes to map done in Custom Importer are not being saved

Open mikest34 opened this issue 4 years ago • 2 comments

Hi Sean, I've got a custom importer that modifies objects on an object layer in Tiled that are marked with a custom property.

I am adding a component and setting a tag value to each object with the custom property. the tag value will match the property value.

Everything works fine on import. the component is there and the tag is set BUT it seems the map is not being set as dirty because when i close and reopen the editor, the component and tag are missing and the map has to be reimported.

I checked my code again against the example provided and didn't notice any step to set the map dirty.

When I added this to the script it does seem to solve the problem so I would suggest adding that to the example or perhaps add some cleanup step to the import routine to do this behind the scenes. EditorUtility.SetDirty(args.AssetImporter);

(i just searched for SetDirty in your code to see what was missing and found it in the TiledAssetImporter.ApplyDefaultSettings method so i knew that was probably the issue on my side)

mikest34 avatar Oct 06 '21 13:10 mikest34

Hi there, @mikest34. Thanks for the advice but a question remains: Where do you suggest I add the call to EditorUtility.SetDirty();? If you could be a little bit more specific that would be great. Thanks.

Seanba avatar Oct 06 '21 17:10 Seanba

hey @Seanba sorry for the delayed response. My thought was to add it in the documentation.

https://supertiled2unity.readthedocs.io/en/latest/manual/extending-the-importer.html#custom-importers

// The AutoCustomTmxImporterAttribute will force this importer to always be applied.
// Leave this attribute off if you want to choose a custom importer from a drop-down list instead.
[AutoCustomTmxImporter()]
 public class MyTmxImporter : CustomTmxImporter
 {
     public override void TmxAssetImported(TmxAssetImportedArgs args)
     {
         // Note: args.ImportedSuperMap is the root of the imported prefab
         // You can modify the gameobjects and components any way you wish here
         // Howerver, the results must be deterministic (i.e. the same prefab is created each time)
         var map = args.ImportedSuperMap;
         Debug.LogFormat("Map '{0}' has been imported.", map.name);
         // You also need to se the imported asset dirty if you make changes to it 
         EditorUtility.SetDirty(args.AssetImporter);
     }
 }

mikest34 avatar May 06 '22 21:05 mikest34