Hello Guest

Author Topic: MeshColliders in RunTime  (Read 4099 times)

axelucho

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
MeshColliders in RunTime
« 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: MeshColliders in RunTime
« Reply #1 on: September 20, 2013, 11:58:20 pm »
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.

axelucho

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: MeshColliders in RunTime
« Reply #2 on: September 21, 2013, 12:50:03 am »
Ohh I see, that explains a lot. Thanks!