Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Amitloaf · Jan 26, 2014 at 10:14 AM · colliderspritebug

Problem with adding dynamic polygon collider 2d

When attaching a PolygonCollider2D to a Sprite with this line: gameObject.AddComponent();

It adds a polygon collider of the same shape as the sprite. For some reason this only works in the editor. On web or windows builds the colldier is messed up and usually much bigger or smaller. Am I doing something wrong or is it just a bug?

Comment
Add comment · Show 8
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 Invertex · Jan 26, 2014 at 10:18 AM 0
Share

$$anonymous$$ight be a bug. How come you are creating it through scripting though? Why not have it pre-added, and merely disable it when you don't want it to be used?

avatar image Amitloaf · Jan 26, 2014 at 10:52 AM 0
Share

Because the sprite is taken randomly from an array. So I can't really know what the collider should look like.

avatar image Invertex · Jan 26, 2014 at 10:54 AM 0
Share

But this sprite array is still a limited amount of sprites. Why not just have them be existing prefab objects with polygon colliders already attached? Generating a new polygon collider during gameplay is an expensive operation.

avatar image Amitloaf · Jan 26, 2014 at 11:00 AM 0
Share

$$anonymous$$ight be, but it happens only once in the beginning of a level, only for the main character. All other colliders are primitives. For a one-time operation, it's not that expensive.

True about the array, but that way you can't download new graphics from the web for example or create them at run time.

I actually currently create premade colliders for everything in the array and it works, so I guess I don't need help anymore on how to solve it, but more to find if it's a bug I guess :D

Thanks!

avatar image schmidj42 · Jan 31, 2014 at 07:28 PM 1
Share

I also have this issue. Works fine in the editor, but not in the web player. I am wondering if it occurs because of any optimization being done.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Wiki

Answer by Kalocyte · Aug 07, 2014 at 06:54 PM

I found the solution to this problem if someone still runs into it. I checked my output log from the development build and it said:

Sprite outline generation failed - could not read texture pixel data. Did you forget to make the texture readable?

You have to set your sprites' type to Advanced and enable the Read/Write box. At least the ones on which you are going to put a Polygon Collider.

Comment
Add comment · Show 4 · 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
avatar image alok-kr-029 · Apr 03, 2015 at 12:55 PM 1
Share

HI $$anonymous$$alocyte is it possible to set sprites' type to Advanced and enable the Read/Write box at run time

avatar image ClearRoseOfWar · Aug 10, 2016 at 03:33 PM 0
Share

I dont understand why this isn't the best answer, because its THE answer. Anyway, hopefully the poster @Amitloaf will fix that :P I rewarded you points, @$$anonymous$$alocyte for your awesome help!

avatar image scaryguy · Jun 23, 2017 at 07:08 AM 0
Share

$$anonymous$$an... I've been spending 2 days to solve this problem!!! THAN$$anonymous$$ YOU!! I've just sign-in first time to the forum just to thank you! :)

avatar image mykbn · Jan 31, 2020 at 02:08 PM 0
Share

In case anyone else runs into this, I also needed to set the Sprite Atlas that the sprite belongs to to "Enable Read/Write".

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

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with sprites. 0 Answers

Flickering Sprites 0 Answers

Collider Mask Bug 0 Answers

Finding a certain variable is failing 0 Answers

How to achieve 2D pixel perfect collision physics (like Badland) in Unity3D ? 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