2D Toolkit Forum

2D Toolkit => Support => Topic started by: sniperjp02 on November 26, 2013, 05:18:15 am

Title: Collider Issue in 4.3
Post by: sniperjp02 on November 26, 2013, 05:18:15 am
Hello all,

I am using 2D Toolkit 2.3 with Unity 4.3 and I keep running into an odd issue.
Sometimes when I edit a texture I see 2 different types of "weirdness".

I am using polygon colliders for most game objects and box colliders for simpler objects.
I see these issues when I edit a texture externally (update graphic in Illustrator and export using Photoshop to the Asset folder).

I would like to know the proper process for updating textures as I see the following:

1. If I change the dimensions of the original texture the sprite will have the new texture but the collider will still have the old dimensions. When I edit the collider in the collection everything looks good. When I go back to the editor I can see the collider does not indeed match the dimensions of the sprite.

2. I randomly see huge performance drops and after investigating I found that for some reason my game objects will randomly duplicate the colliders attached to them. Sometimes a single object will have over 30 colliders.

I appreciate any insight on these problems and if I am doing something wrong I could really use some advice on what the proper process is. This has happened at least 3 times now and it is very time consuming to repair the state of my objects.

Thanks,
Jacob
Title: Re: Collider Issue in 4.3
Post by: unikronsoftware on November 26, 2013, 09:52:19 am
Are you using 2d or 3d physics?
1. How have you configured the collider in the sprite collection editor?
2. Is this due to changing the textures externally?
Title: Re: Collider Issue in 4.3
Post by: sniperjp02 on November 27, 2013, 04:31:14 am
Thanks for the reply unikron.

I am using 2D physics and this project was originally created in 4.3 with 2D presets selected.

1. I was originally using the 2D ColliderGen asset to auto-trace the sprites and then hand tweaked them. After seeing this issue a few times I stopped using it to see if it would happened again, which it has. I am creating the polygon colliders by hand and using custom box colliders on simpler objects now. I am pretty sure only the polygon colliders are being duped.
2. Yes I am changing the textures externally and then opening the sprite collection which contains the changed texture and editing the collider. Sometimes I change the texture while the project is open in Unity and other times Unity was closed.

Should I only edit textures with Unity open?
Have you seen anything like this before or do you think it is an issue with 4.3?

I will try to find a reproducible case if I can.

Thanks again,
Jacob
Title: Re: Collider Issue in 4.3
Post by: sniperjp02 on November 27, 2013, 05:10:57 am
Ok, so I seemed to have found a reproducible case for the collider duplication issue.

Steps:

1. Create a Sprite Collection.
2. Add texture (I use point filter, 2D Physics, and have 1x and 2x sprites for settings).
   2a. Create polygon collider and commit.
3. Create a new tk2d sprite using the new sprite.
4. Rename and add a 2D Rigidbody and create a prefab from the object.
------Up to here everything is fine------
5. Create new texture in Photoshop and overwrite the texture and @2x version in the asset folder (with Unity open).
6. Open the Sprite Collection and click commit, the collider will be duped at this point for all sprites in this collection that are in the scene.

Normally I would edit the collider in step 6 but I found that is not necessary to reproduce this behavior.

I assume this behavior is not expected.
For now I will try to avoid editing textures once they are in the project.

Please let me know if the steps I take are not "standard" or if I should be doing something else.

Thanks,
Jacob

Title: Re: Collider Issue in 4.3
Post by: unikronsoftware on November 28, 2013, 11:04:44 am
This is expected use case and should work properly. It is likely a bug - I will investigate this. Thanks for the comprehensive repro case.
Edit: I've been attempting to reproduce this and I don't seem to be able to. Would it be possible to email a repro project where its at step 5? Should be able to catch it pretty easily then.
Title: Re: Collider Issue in 4.3
Post by: sniperjp02 on November 28, 2013, 05:45:41 pm
Hello unikron,

I was unable to reproduce this in a clean project.

After I added the 2D ColliderGen plugin to the project I was able to reproduce it.
In my other project I still had 2D ColliderGen added but was not using it.
I will remove it from the project for now and contact support for that plugin.

Thanks for the help,
Jacob
Title: Re: Collider Issue in 4.3
Post by: TheMightyGit on December 04, 2013, 10:36:43 am
This is expected use case and should work properly. It is likely a bug - I will investigate this. Thanks for the comprehensive repro case.
Edit: I've been attempting to reproduce this and I don't seem to be able to. Would it be possible to email a repro project where its at step 5? Should be able to catch it pretty easily then.

I get duplicated 2D Polygon Colliders on my main spaceship every time I hit 'play'. Without fail. As far as I know I'm not doing anything exotic. It's just a prefabbed tk2d sprite with an animator and 2 attach points (one of the attach points has a tk2d sprite in it).  However, it also happens to the baddies, but far less often (they tend to be inactive in edit mode, tho).

As yet I cannot identify the difference between when the excess ones get added to the ship and baddies.
Title: Re: Collider Issue in 4.3
Post by: TheMightyGit on December 04, 2013, 10:43:02 am
I get duplicated 2D Polygon Colliders on my main spaceship every time I hit 'play'. Without fail. As far as I know I'm not doing anything exotic. It's just a prefabbed tk2d sprite with an animator and 2 attach points (one of the attach points has a tk2d sprite in it).  However, it also happens to the baddies, but far less often (they tend to be inactive in edit mode, tho).

As yet I cannot identify the difference between when the excess ones get added to the ship and baddies.

Setting the initial sprite to one with a 'force none' collider works around the issue.
Title: Re: Collider Issue in 4.3
Post by: TheMightyGit on December 04, 2013, 10:49:17 am
Setting the initial sprite to one with a 'force none' collider works around the issue.

Odder still, now when I switch back to an initial sprite with a collider - it still works properly!
Title: Re: Collider Issue in 4.3
Post by: unikronsoftware on December 04, 2013, 10:59:11 am
Very odd indeed - there could be some weird case I'm not handling properly. Please let me know if you find out whats causing this.
Title: Re: Collider Issue in 4.3
Post by: TheMightyGit on December 05, 2013, 05:12:22 pm
Very odd indeed - there could be some weird case I'm not handling properly. Please let me know if you find out whats causing this.

It was fine for a while, now I've got 20+ 2D Poly Colliders on my ship again. Was fine all yesterday, didn't notice when or why it started to happen again.  Will try and keep a sharper eye out.
Title: Re: Collider Issue in 4.3
Post by: TheMightyGit on December 05, 2013, 05:50:32 pm
Very odd indeed - there could be some weird case I'm not handling properly. Please let me know if you find out whats causing this.

It was fine for a while, now I've got 20+ 2D Poly Colliders on my ship again. Was fine all yesterday, didn't notice when or why it started to happen again.  Will try and keep a sharper eye out.

Ahh! Got it. After I 'commit' my sprite collection, all subsequent 'play' presses cause an extra 2D Poly Collider to appear.
Title: Re: Collider Issue in 4.3
Post by: unikronsoftware on December 05, 2013, 06:34:36 pm
Can you send me a repro of this? I haven't been abel to reproduce it on my end. support at unikronsoftware.com
Title: Re: Collider Issue in 4.3
Post by: jinyangnet on December 09, 2013, 02:49:18 pm
I am also the same problem , add more than 100 PolygonCollider2D...

Had no choice but to Modify UpdateCollider ()  stop continue to increase PolygonCollider2D
PolygonCollider2D [] poly = gameObject.GetComponents ();
if (poly.Length> 0) return;


Hello all,

I am using 2D Toolkit 2.3 with Unity 4.3 and I keep running into an odd issue.
Sometimes when I edit a texture I see 2 different types of "weirdness".

I am using polygon colliders for most game objects and box colliders for simpler objects.
I see these issues when I edit a texture externally (update graphic in Illustrator and export using Photoshop to the Asset folder).

I would like to know the proper process for updating textures as I see the following:

1. If I change the dimensions of the original texture the sprite will have the new texture but the collider will still have the old dimensions. When I edit the collider in the collection everything looks good. When I go back to the editor I can see the collider does not indeed match the dimensions of the sprite.

2. I randomly see huge performance drops and after investigating I found that for some reason my game objects will randomly duplicate the colliders attached to them. Sometimes a single object will have over 30 colliders.

I appreciate any insight on these problems and if I am doing something wrong I could really use some advice on what the proper process is. This has happened at least 3 times now and it is very time consuming to repair the state of my objects.

Thanks,
Jacob
Title: Re: Collider Issue in 4.3
Post by: unikronsoftware on December 10, 2013, 02:46:12 pm
I've updated the code for the next version - it should detect this a lot better. Let me know how that goes once its released.
Title: Re: Collider Issue in 4.3
Post by: TheMightyGit on December 10, 2013, 02:47:05 pm
I've updated the code for the next version - it should detect this a lot better. Let me know how that goes once its released.

Thank you!
Title: Re: Collider Issue in 4.3
Post by: Tiltgames on December 16, 2013, 05:14:46 pm
Hi everybody,

seems that the issue is still there. I'm using 2D Toolkit v2.3.3 with Unity 3D v4.3.1f1.
Here is what happens to me:
If I have a sprite with a user defined collider as a prefab, switching the collider to polygon will result in duplicated colliders everytime I hit play. Quick fix: To switch the collider I had to delete the collider from the sprite and then setting the collider to polygon. Or is this normal?

Thanks and best regards
Title: Re: Collider Issue in 4.3
Post by: unikronsoftware on December 17, 2013, 09:51:14 pm
If you can definitely reproduce this, please email a repro example to support at unikronsoftware.com - I thought the 4.3.3 update should've put a stop to this and I can't reproduce this any more, but perhaps I've missed something?
Title: Re: Collider Issue in 4.3
Post by: kreso22 on March 02, 2015, 05:14:10 am
This is happening to me too.
I can't make a repro - but I did a fix that works for me. Just attached this script to object containing sprite/colliders

[ExecuteInEditMode]
public class FixBugWPolygonColliders : MonoBehaviour {
void Start () {
      //remove all collider duplicates (tk2d bug)
      PolygonCollider2D[] colls = gameObject.GetComponents<PolygonCollider2D>();
      bool originalCol = false;
      foreach (PolygonCollider2D col in colls)
      {
         if (!originalCol)
         {
            originalCol = true;
         } else
         {
            #if UNITY_EDITOR
            DestroyImmediate (col);
            #else
            Destroy (col);
            #endif
         }
      }
   
   }
}
Title: Re: Collider Issue in 4.3
Post by: huminaboz on January 10, 2016, 12:31:40 am
Thanks Kreso22, this fixed my problem.