Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to map done in Custom Importer are not being saved #192

Open
mikest34 opened this issue Oct 6, 2021 · 2 comments
Open

Changes to map done in Custom Importer are not being saved #192

mikest34 opened this issue Oct 6, 2021 · 2 comments

Comments

@mikest34
Copy link

mikest34 commented Oct 6, 2021

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)

@Seanba
Copy link
Owner

Seanba commented Oct 6, 2021

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.

@mikest34
Copy link
Author

mikest34 commented May 6, 2022

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);
     }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants