2D Toolkit Forum
2D Toolkit => Support => Topic started by: vsn3e8 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
-
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?)
-
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?)
-
How do you spawn the sprite itself?
-
GameObject.Instantiate(m_cachedSprites[spriteId]);
How do you spawn the sprite itself?
-
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.
-
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.
-
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.
-
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.
-
Replied to your email.
-
Same issue here. What can we do?
-
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.
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;
}
}