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

Stuck importing map with unity:resource True #26

Closed
dpavon opened this issue Jan 3, 2016 · 4 comments
Closed

Stuck importing map with unity:resource True #26

dpavon opened this issue Jan 3, 2016 · 4 comments

Comments

@dpavon
Copy link

dpavon commented Jan 3, 2016

Hi, I've been using Tiled2Unity with some procedural generation, and for maps to be generated in execution, I needed tmx processed prefabs to be stored in Resources folder, but something happens and importing gets stuck on "Create prefab: XX".

I've been debugging for a while, and it seems that in "TiledAssetPostProcessor.OnPostprocessAllAssets()", last call of the loop is for the prefab itself. If it is processed correctly, then "ImportFinished" is called, but this doesn't happen in this case.

I would take a look at "TiledAssetPostProcessor.UseThisImporter()", as for the prefab case with unity:resource=True, the folder path (exportMarkerPath) is something like: "PROJECTROOT\Assets\Tiled2Unity\Prefabs\Resources..\Tiled2Unity.export.txt", which does not consider the "Resources" case, and seems to look for the export.txt inside "Prefabs" instead of inside "Tiled2Unity".

I'm going to hack my code to avoid this problem, but as I don't know this library enough, for now I will not suggest a pull request until I'm 100% sure it doesn't break anything. In any case, I'm sure you guys will find a better and more general solution :)

Just in case, I'm using unity 5.3.1f1, Tiled2Unity-1.0.1.1, and Tiled 0.14.2

@Seanba
Copy link
Owner

Seanba commented Jan 3, 2016

Hi dpavon, thanks for reporting this and taking the time to track down the errant code. I've updated the source on GitHub and put up a new version to Tiled2Unity with the fix on my blog.

Good luck on your game.

@dpavon
Copy link
Author

dpavon commented Jan 3, 2016

That was fast! Thanks a lot! (tested and it works)

By the way, I've got a suggestion, but I'm not sure if it's something too specific or if anyone else could benefit. As I said with the procedural generation, I need to load Resources prefabs in runtime:

In execution time, I will not know all the names of the resources, so I need to find them all somehow. I tried first with storing some kind of "index", like a cache or similar, but I don't like it and has some drawbacks.

The thing is, Unity has a method called LoadAll to do this that gives you the option to specify a relative path inside "Resources" folder, and all those prefabs inside would be loaded as Object[]. Right now in Tiled2Unity, all maps are imported either on Tiled2Unity/Prefabs, or in case this boolean is True, on "Tiled2Unity/Prefabs/Resources".

So, in short: could there be the possibility of using this "unity:resource" as a string, instead of a boolean, so that anyone could specify the folder where each map would be saved?

Example: 3 tmx maps with different unity:resource = [Forest, Lake, Mountain], and these maps would be imported on "Tiled2Unity/Resources/Forest/", "Tiled2Unity/Resources/Lake/", "Tiled2Unity/Resources/Mountain/" folders. At runtime, the developer would use LoadAll("Lake") to obtain only those needed.

Anyway, I'm not sure if using another property would be better, like "unity:resourcePath", because an empty (but existing) unity:resource="" might confuse users. I leave this open to suggestions.

Right now I'm modifying the output folder so I have all maps in a folder called "Tiled", so it's not something I would desperately need, but maybe someone could benefit of a change like this. I'm not sure if it is a minor or big change, so I'll just drop this idea over here.

Then again, great work, keep it up! You may consider this issue closed by my side.

@Seanba
Copy link
Owner

Seanba commented Jan 3, 2016

That's a good suggestion. I went with the unity:resourcePath approach.

You will be alerted if you use characters in your string that can't be used in a path (like '|', '<', '>', etc.).

Code and download page has been updated. Let me know if you run into any issues.

@Seanba
Copy link
Owner

Seanba commented Jan 3, 2016

Also, note that you don't have to use both unity:resource and unity:resourcePath together. In your case, using unity:resourcePath and having it set to a non-empty string will suffice. Having just unity:resource will resort to the old behavior. There's no harm in having both properties used as unity:resourcePath will take precedence.

@Seanba Seanba closed this as completed Jun 5, 2016
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