Hello Guest

Author Topic: "Invalid Mesh Collider on Sprite, please remove and try again"  (Read 10212 times)

josriley

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
"Invalid Mesh Collider on Sprite, please remove and try again"
« on: November 23, 2012, 07:42:59 pm »
I'm not sure what's causing this, but I get this message anytime I instantiate almost any of my (animated, for what its worth) sprites. It appears to come from the CreateCollider() method in the base sprite class. It seems like its not getting the collider data from the Sprite Collection at run time. Any idea what the problem is?

Also, it doesn't seem to affect anything other than distorting my polygon colliders, and also only seems to affect my standalone builds, not my web builds.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: "Invalid Mesh Collider on Sprite, please remove and try again"
« Reply #1 on: November 23, 2012, 08:16:44 pm »
Hi,

That error is triggered when the sprite has the incorrect collider type. For example, if you had an animated sprite, but used a polygon collider, but another frame uses a box collider, or something like that.If you're animating sprites, keep it to box, as you can't really animate poly colliders.

josriley

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: "Invalid Mesh Collider on Sprite, please remove and try again"
« Reply #2 on: November 23, 2012, 08:38:36 pm »
Thanks for replying so quickly!

I really only have one actual animation, and all frames are box colliders with the exact same image and collider dimensions. The rest were just one frame "animations" because I was planning to do the artwork later, and didn't want to rewrite code when I do. I've since temporarily changed those to sprites.

However, I'm still getting the error message, and still getting the messed up polygons on my now unanimated sprites, even before I instantiate an animated sprite and get the error message.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: "Invalid Mesh Collider on Sprite, please remove and try again"
« Reply #3 on: November 23, 2012, 08:45:13 pm »
Thats bizzare, and unexpected. Can you get me a test case to look at? Always worth asking first to avoid a long winded back-and-forth :) If so, email support@unikronsoftware.com

josriley

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: "Invalid Mesh Collider on Sprite, please remove and try again"
« Reply #4 on: November 24, 2012, 06:54:09 pm »
Looked at it again with fresh eyes, and I'm an idiot...It looks like the distorted colliders are because the colliders aren't flipping when I flip the sprite (using the FlipX method in code), which I assume is expected behavior. I'm still not sure why I'm getting the error message, but it doesn't seem to be affecting anything at all in my game. I'd be happy to send you my project if you want to still take a look, though.

Also, do you know of a way I could solve the new problem? I can think of a few workarounds, like having separate sprites, or creating a second prefab that is flipped before runtime (clicking Hflip in the inspector correctly flips the collider), but I'm guessing I've missed something simple.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: "Invalid Mesh Collider on Sprite, please remove and try again"
« Reply #5 on: November 24, 2012, 08:11:37 pm »
Yeah - using HFlip / scale in the sprite component reconstructs the collider in the editor. You should avoid modifying polygon colliders at runtime - they are expensive, but if you still want to do it, use the built in transform component as opposed to the sprite.scale. That will work.

josriley

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: "Invalid Mesh Collider on Sprite, please remove and try again"
« Reply #6 on: November 25, 2012, 09:20:52 pm »
Thanks for the help. I switched to 2D Toolkit from Orthello a few weeks ago and love it! It probably makes my workflow twice as fast, not to mention making my games more efficient several times over.