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

Performance issues #235

Open
inspirsea opened this issue Feb 7, 2023 · 8 comments
Open

Performance issues #235

inspirsea opened this issue Feb 7, 2023 · 8 comments

Comments

@inspirsea
Copy link

Hi, great plugin. Have used it for a while now and it works really well its exactly what I need for easy integration to unity.

However when we make changes in tiled it takes an awful long time to reimport the changes. This is have started to become an issue when our maps have gotten more numerous a swell as more complex.

I believe the main problem is the polygon collider, but could be mistaken.
I set up a minimalistic unity project exemplifying the issue.

https://github.com/inspirsea/SuperTiledPerformanceTest

This project takes around 10min to reimport the map if I make a change in tiled. This seems a bit excessive as the map is quite small and doesn't use a lot of different tiles. I would be grateful if you could take a look at the issue. Either if there is some optimization issue, bug or incorrect setup on my side.

@seanb-22ct
Copy link
Collaborator

Hi there, @inspirsea. Thanks for putting together a test project on Github for me to play with.

I'll take a look at this later on today but head's up that the problem might be that you are using a sub-pixel points in the collision editor for your tiles. That causes a lot of slivers and degenerate polygons. It's hard for any algorithm to merge that can kind of geometry, at least quickly.

FWIW, ST2U uses Clipper for combining colliders. It's a great piece of software that is battle-tested and widely-used but there's only so much it can do.

But I'll take a closer look at your project later to confirm that is your issue. In the meantime you may want to turn on Snap to Pixels in Tiled.

image

@seanb-22ct
Copy link
Collaborator

Okay, there are some issues with your tile collider geometry afterall which is going to greatly effect performance of the importer.

I'm going to post these as I find them.

The biggest contribution to the slow import times is your tiles that have both ice and water regions ...

image

You want those collisions to have nice and even points on pixel boundaries (not bleeding outside the tile if possible).

image

Further, you want to put those colliders on separate physical layers. That part is essential otherwise you end up crazy collision shapes that are expensive to compute.

image

image

image

@seanb-22ct
Copy link
Collaborator

A lot of your tiles have sub-pixel X,Y values, have sub-pixel points/nodes on their polygons, have extra points they don't need, they bleed outside the tile, and they are all grouped into the Default collision layer (because they are not using unity:layer).

Like this ...

image

But this is better ...

image

(Pixel snapping in Tiled will fix up having sub-pixel coordinates)

@seanb-22ct
Copy link
Collaborator

Here's an example where you should use rectangles instead of polygons. Place them with pixel snapping and put the them in different water and ice Unity layers.

image

@seanb-22ct
Copy link
Collaborator

I went through some of tiles and cleaning up their collisions made the (re)import go from 10 minutes down to 30 seconds.

That's still too long IMHO but if you follow suit with the other colliders in the Tile Collision Editor (in Tiled) then you should be in good shape.

I've attached my changes to your Winter.tsx file (with a txt extension so I can post). Note that you will need to add the Ice layer to your Tag Manager settings in Unity.

Winter.tsx.txt

@seanb-22ct
Copy link
Collaborator

Also, if you make me a contributor your Github project then I can just push up my changes in a separate branch.

@inspirsea
Copy link
Author

inspirsea commented Feb 8, 2023

Hi thanks for your swift reply and massive help.
I send you an invite if you want to commit your changes. Will make sure to make the suggested changes. Will be really interesting to see how this affects the import speed in the main project.

Super useful information on what might effect the import speed. More help than I could ask for.

Thanks a bunch!

@seanb-22ct
Copy link
Collaborator

I've pushed up my changes to your GitHub under the collision_refactor branch. That should give you a good idea of the kind of changes I needed to make to make the importing go faster.

Once you complete cleaning on the collisions and put them into Ice or Water physical layers then you should be in good shape. Let me know if you have any questions.

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