Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tmendez · Nov 04, 2015 at 08:09 AM · androidspriteboxcollider2doverlappolygoncollider2d

Does PolygonCollider2D.OverlapPoint() perform differently in Unity player than an Android device?

I'm checking to see if a point is within a run-time generated PolygonCollider2D on a run-time generated Sprite and am using OverlapPoint(point) to check this. I get the exact expected behavior on the Unity player, but when compiled into an APK and loaded on my Android phone, OverlapPoint(point) returns true in what looks to be like a BoxCollider2D around the Sprite. The Sprite is a leaf and not a box.

Behavior on Unity Player:

Behavior on Android device:

Anyone have any idea what's going on? I'm lost!

Thanks

p.s. yes it's the most updated freshly-compiled apk

spritecolliderthing.png (71.5 kB)
boxcollider.jpg (351.4 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tmendez · Nov 04, 2015 at 09:05 AM 0
Share

I think it has to do with the way the PolygonCollider2D is generated on the sprite on the device. Any workarounds?

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by tmendez · Nov 04, 2015 at 08:24 PM

OKAY I FIGURED IT OUT GUYS. GOSH DANG THAT WAS ROUGH.

After hours and hours of scouring the web and piecing everything together I was able to figure out the problem: PolygonCollider2D is more inaccurate when created and scaled at runtime on a device

I was creating a new Sprite each time, and adding a PolygonCollider2D to it, which worked fine in the editor. However it does not work fine on my mobile device, generating a generally much larger collider.

I call this fix The Angry PolygonCollider Bandaid:

  1. Force the PolygonCollider2D to be generated by the Unity Editor
       Drag your image onto the object hierarchy to create a new Sprite. Scale the Sprite at (0,0,0) from within the inspector. Click 'Add Component' and add a PolygonCollider2D.

  2. Clone the created Sprite that has the Unity Editor generated PolygonCollider2D
       Create a public reference to your Sprite from within your script, along the lines of public GameObject prerenderedSprite;. Drag your Sprite from the inspector onto the prerenderedSprite variable of your script.
       Clone the object by GameObject clonedSprite = Instantiate(prerenderedSprite);

  3. Scale the new sprite to your liking
       Now that you have your sprite, you can scale it dynamically without fear of an inaccurate PolygonCollider2D.
        clonedSprite.transform.localScale = new Vector2(scaleX, scaleY);

Your sprite will be just as accurate as it is in the Unity Edtior.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D Box Colliders Overlapping On Collision 4 Answers

[Android] Bad Rendering for whole Canvas UI. Change sprite image run-time after clicked 0 Answers

Screen resolution make sprites pixelated 0 Answers

Non transparent areas of sprites becomes transparent on android 1 Answer

Why does my sprite on Android device get blurry? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges