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

Tiled2Unity files for use with A* search algorithm #32

Closed
hsdk123 opened this issue Mar 27, 2016 · 7 comments
Closed

Tiled2Unity files for use with A* search algorithm #32

hsdk123 opened this issue Mar 27, 2016 · 7 comments

Comments

@hsdk123
Copy link

hsdk123 commented Mar 27, 2016

Hi, I've been using Tiled2Unity for my map imports. Things were great, but now I need to start implementing path searches from one part of the map to another (without colliding with any of the colliders), but this seems very difficult with the current map import method as the maps are just saved as textures instead of tiles (or any form of nodes).

Do you have any recommendations on how A* could be implemented on top of the Tile2Unity import file? If this currently seems undoable, it would be great if an update could be made to make this possible.

@Seanba
Copy link
Owner

Seanba commented Mar 27, 2016

Hi there. I suggest using Tiled's automapping features in combination with
a Tiled2Unity custom importer. In Tiled, you can have the automapping place
Objects in an Object Layer. These objects will be exported to your Unity
project as GameObjects with whatever custom properties you need. You would
then write a custom importer to process those GameObjects in whatever way
suits you -- perhaps as nodes in an A* graph.

It will take a little bit of work but it's totally doable. I've thought of
adding this as a feature before but I doubt I could make it generic enough
for most games. (Pathfinding needs is actually one of the reasons I made
Tiled2Unity to be expanded through the use of custom importers.)

On Sat, Mar 26, 2016 at 11:07 PM, hsdk123 notifications@github.com wrote:

Hi, I've been using Tiled2Unity for my map imports. Things were great, but
now I need to start implementing path searches from one part of the map to
another (without colliding with any of the colliders), but this seems very
difficult with the current map import method as the maps are just saved as
textures instead of tiles (or any form of nodes).

Do you have any recommendations on how A* could be implemented on top of
the Tile2Unity import file? If this currently seems undoable, it would be
great if an update could be made to make this possible.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#32

@hsdk123
Copy link
Author

hsdk123 commented Mar 27, 2016

Hi Sean, thanks for the reply. I get the feeling that having a checkbox option of saving all tiles as individual game objects would be more than fine for a lot of cases (with just an added warning message saying that we can get O(n2) performance issues).

I'm trying the automapping recommendation for the moment though (following the post here: http://www.seanba.com/getting-tile-information.html), but I don't quite understand how the custom importer works - more specifically, I don't quite know where I should be putting the file, and how I should be incorporating it into the import process. Is there a step by step tutorial for this by any chance?

@hsdk123
Copy link
Author

hsdk123 commented Mar 27, 2016

I'm also realising that with the automapping feature, the auto added tiles, after the regular import, are also just imported as 1 large game object like the other tiles. Is this supposed to be happening, or have I misused the automapping feature?

Here's the map I'm currently testing with the rules included (test_rooms.txt)
The auto added tiles are placed in the 'Graph' layer.

maps-hsdk.zip

@Seanba
Copy link
Owner

Seanba commented Mar 27, 2016

I can't open TMX files without the images that go with them but eyeballing
the rule1.tmx file in a text editor it looks like your output is another
tile. I'm suggesting you output not a tile to a Tile Layer but an object to
an Object layer. These get imported as GameObjects on the Unity side of
things.

For custom importers I talk about them a bit here:
http://www.seanba.com/megadadadventures.html

I don't think the option of exporting every single tile as an object is a
good idea. Even for small maps your GameObjects will quickly grow in number
past tens of thousands of objects. For traditional A* not all tiles are
going be used anyhow and some users are going to want to use nav meshes for
pathfinding instead (in this case, using the generated PolygonCollider2D
objects may be a better approach).

(BTW, you may want to use TSX files so that you don't have to re-import the
15 or so tilesets for every TMX file you work with. Just a thought.)

Best,
Sean

On Sun, Mar 27, 2016 at 1:41 PM, hsdk123 notifications@github.com wrote:

I'm also realising that with the automapping feature, the auto added
tiles, after the regular import, are also just imported as 1 large game
object like the other tiles. Is this supposed to be happening, or have I
misused the automapping feature?

Here's the map I'm currently testing with the rules included
(test_rooms.txt)
The auto added tiles are placed in the 'Graph' layer.

maps-hsdk.zip
https://github.com/Seanba/Tiled2Unity/files/191040/maps-hsdk.zip


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#32 (comment)

@hsdk123
Copy link
Author

hsdk123 commented Mar 27, 2016

Thanks for the quick replies - I'm trying to get the custom importer working, but Unity gives me

Assets/Tiled2Unity/CustomImporter.cs(10,36): error CS0234: The type or namespace name `ICustomTiledImporter' does not exist in the namespace `Tiled2Unity'. Are you missing an assembly reference?

errors. Would you have any idea as to what might be happening?

My custom import script is just the below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEditor;
using UnityEngine;

[Tiled2Unity.CustomTiledImporter]
class CustomImporter : Tiled2Unity.ICustomTiledImporter
{
    public void HandleCustomProperties(GameObject gameObject,
        IDictionary<string, string> keyValuePairs)
    {
        Debug.Log("Handle custom properties from Tiled map");
    }

    public void CustomizePrefab(GameObject prefab)
    {
        Debug.Log("Customize prefab");
    }
}

@Seanba
Copy link
Owner

Seanba commented Mar 27, 2016

Editor scripts must be in a folder named "Editor".

Assets/Tiled2Unity/CustomImporter.cs (won't compile)
Assets/Tiled2Unity/Editor/CustomImporter.cs (will compile)

... but I recommend you keep your custom scripts outside of the Tiled2Unity
folder and put it somewhere like ...

Assets/YourGameScriptFolder/Editor/CustomImporter.cs

Hope that helps,
Sean

On Sun, Mar 27, 2016 at 2:19 PM, hsdk123 notifications@github.com wrote:

Thanks for the quick replies - I'm trying to get the custom importer
working, but Unity gives me

Assets/Tiled2Unity/CustomImporter.cs(10,36): error CS0234: The type or namespace name ICustomTiledImporter' does not exist in the namespaceTiled2Unity'. Are you missing an assembly reference?

errors. Would you have any idea as to what might be happening?

My custom import script is just the below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEditor;
using UnityEngine;

[Tiled2Unity.CustomTiledImporter]
class CustomImporter : Tiled2Unity.ICustomTiledImporter
{
public void HandleCustomProperties(GameObject gameObject,
IDictionary<string, string> keyValuePairs)
{
Debug.Log("Handle custom properties from Tiled map");
}

public void CustomizePrefab(GameObject prefab)
{
    Debug.Log("Customize prefab");
}

}


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#32 (comment)

@hsdk123
Copy link
Author

hsdk123 commented Mar 29, 2016

Hi Sean, thanks, I managed to get things working. I feel that the explanation on directories would be a great addition to the wiki though.

I'll close this thread then until perhaps I come across what I feel might be a more generic method to allow for pathfinding using Tiled maps. Thanks for the help!

@hsdk123 hsdk123 closed this as completed Mar 29, 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