Hello Guest

Author Topic: Strange bug, destroying gameobject destroys ALL colliders  (Read 8308 times)

vsn3e8

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Strange bug, destroying gameobject destroys ALL colliders
« on: May 20, 2013, 09:06:13 pm »
I'm running into a strange bug where by destroying a single instance of a game object with a tk2dsprite seems to screw up or destroy all colliders of every other instance of that same sprite.

edit:

Dug around a little, appears to be caused by the destruction of the shared mesh
« Last Edit: May 20, 2013, 10:23:27 pm by vsn3e8 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #1 on: May 21, 2013, 08:24:54 am »
I presume you're talking about mesh colliders here?
Also, can you pelase give me more info to investigate this with:
1. Unit version
2. 2D Toolkit version
3. How you're creating the sprite (instantiate, I guess?)




vsn3e8

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #2 on: May 21, 2013, 06:05:34 pm »
unity ver 4.1.2f
2d ver 1.92 final

I first run through and create caches of all collection data.
All sprites are then instantiated off of cached version's which are cached by a unique identifier.



I presume you're talking about mesh colliders here?
Also, can you pelase give me more info to investigate this with:
1. Unit version
2. 2D Toolkit version
3. How you're creating the sprite (instantiate, I guess?)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #3 on: May 21, 2013, 07:20:58 pm »
How do you spawn the sprite itself?

vsn3e8

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #4 on: May 22, 2013, 08:08:28 pm »
GameObject.Instantiate(m_cachedSprites[spriteId]);



How do you spawn the sprite itself?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #5 on: May 23, 2013, 01:52:02 pm »
I've managed to reproduce this, and I know what it is exactly. Just not sure how to "fix" this without making it take a lot longer to initialize. I can give you a tmp fix if you want. Email support at unikronsoftware dot com and I'll give you a script to work around this.

vsn3e8

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #6 on: May 23, 2013, 10:15:38 pm »
Sure will do.

The workaround I have currently is to simply not destroy the shared mesh collider and take the hit of leaving that guy around. Which isn't actually that offensive for my game.


I've managed to reproduce this, and I know what it is exactly. Just not sure how to "fix" this without making it take a lot longer to initialize. I can give you a tmp fix if you want. Email support at unikronsoftware dot com and I'll give you a script to work around this.

vsn3e8

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #7 on: May 23, 2013, 10:49:37 pm »
So, apparently my workaround does not work on IOS device. Hopefully yours will.



Sure will do.

The workaround I have currently is to simply not destroy the shared mesh collider and take the hit of leaving that guy around. Which isn't actually that offensive for my game.


I've managed to reproduce this, and I know what it is exactly. Just not sure how to "fix" this without making it take a lot longer to initialize. I can give you a tmp fix if you want. Email support at unikronsoftware dot com and I'll give you a script to work around this.

masterhyjinx

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #8 on: June 03, 2013, 10:20:56 am »
I just ran into this exact problem tonight.  Unity version 4.1.2f1 and 2D Toolkit 1.92 Final + patch.  I'm going to e-mail you as well because I wouldn't mind the work around either.  Currently, if I destroy an enemy, every other enemy in the scene's mesh collision disappears. 

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #9 on: June 03, 2013, 10:32:54 am »
Replied to your email.

A3DStudio

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #10 on: June 03, 2013, 12:59:48 pm »
Same issue here. What can we do?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Strange bug, destroying gameobject destroys ALL colliders
« Reply #11 on: June 03, 2013, 01:24:39 pm »
The issue happens occurs when you instantiate a GameObject that is already in the scene. It reuses the same meshcollider for performance. If you change your Instantiate code to something like this, it should work reliably - but please remember that its quite expensive to create meshcolliders on the fly, you want to cache/pool as many of these as possible rather than deleting them and recreating them later.

Code: [Select]
if (sourcePrefab != null) {
                MeshCollider mc = sourcePrefab.GetComponent<MeshCollider>();

                if (mc != null) {
                    mc.sharedMesh = null;
                }
                tk2dBaseSprite sprite = sourcePrefab.GetComponent<tk2dBaseSprite>();
                if (sprite != null) {
                    if (sprite.meshColliderMesh != null) {
                        Destroy(sprite.meshColliderMesh);
                        sprite.meshColliderMesh = null;
                    }
                }
           
                GameObject g = Instantiate (sourcePrefab) as GameObject;
            }
}