Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug PolygonCollider2D components do not work properly in iOS build

Discussion in 'Physics' started by kardelsharpeye639842, Jul 27, 2023.

  1. kardelsharpeye639842

    kardelsharpeye639842

    Joined:
    Jun 27, 2023
    Posts:
    2
    I'm trying to figure out why my polygon colliders default to pentagon shapes when I build my app and test it on a device.

    I have a scene with some blocks you can drag around where the colliders work perfectly fine in the Unity editor and takes the shape of whatever image its attached to.

    However, once I build the app for iOS and run the scene on my device, I've noticed the collision is way off. I created a way to draw the collider during runtime in a build and found that the shape of all the colliders are pentagons.

    Why does this happen? I'd assume that polygon colliders don't work for complicated shapes but the rounded rectangle shape shouldn't be that complicated right?

     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    That wouldn't be a useful limitation but no, PolygonCollider2D don't have any limitations.

    How are they constructed? Have you edited the PolygonCollider2D and they are already sat on the GameObject or are you adding the component at runtime? If so and you want it to adopt the shape of a Sprite then you'll need to ensure that the Sprite has a physics shape (see Sprite Editor) otherwise it won't be able to read the texture of the sprite unless that sprite texture is read/write; something not recommended as it has to be maintained in memory. This isn't specifically iOS but any build.

    Also, what you're drawing there isn't something the PolygonCollider2D would be. It always creates a closed shape so you're drawing it wrong.

    NOTE: I'll move your post to the correct forum.