Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Update 2D Sprite Poly Collider

Discussion in '2D' started by KJoanette, Jan 14, 2014.

  1. KJoanette

    KJoanette

    Joined:
    Jun 8, 2013
    Posts:
    59
    I've been looking at animating a 2D sprite and having the 2d poly collider on it update each frame as well. I'm using a raycast in to my scene to detect "pixel perfect" collision with the generated mesh.

    Unfortunately I've run in to two issues.

    1- Trying to Destroy the collider and re-add one (thus forcing the poly to recalculate) doesn't appear to work. Unity keeps the original collider forever and eventually my gameobject has thousands of colliders attached to it.

    2- When this poly is calculate is it cached at all? Re-adding the collider like this every frame seems like it would be a very bad idea if it is going to do the calculation for it every single time. If that is the case then I will have to look in to caching this collider after it is calculated so that I can simply do a lookup on it in order to avoid the recalculation.

    If anyone has any insight on either of these it would be greatly appreciated.