2D Toolkit Forum
2D Toolkit => Support => Topic started by: axelucho on September 20, 2013, 10:40:56 pm
-
Hi, so I've noticed that sprites with polygon colliders don't update their mesh when setting a new sprite, but after searching around I found out this is intended as it's really expensive to create meshes in runtime which makes sense. My doubt really is the following:
* Why are meshes created in runtime instead of being created in the editor when setting up the sprite collection? If meshes were created outside of runtime I could simply assign them accordingly based on the new sprite.
* Would it be viable for me to: in editor mode, create the mesh files for all the sprites i'm interested in. Attach them all to the prefab containing the sprite collection. And when ever i set a new sprite i can set the according mesh.
I'm not much of a programmer so I hope I'm making sense.
-
Its not creating the mesh that is expensive, but rather assigning it to the mesh collider - thats when Unity converts the mesh to a physx friendly format. You can only have one collider attached to a sprite, and you can't modify the mesh after assigning it - so you have to reassign a new mesh, making things horribly slow and allocate a ton of memory.
You can however, create all the sprites you could possibly switch between, and then show and hide the appropriate sprites to animate the sprite.
-
Ohh I see, that explains a lot. Thanks!