Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 Jtec · Nov 21, 2013 at 02:05 AM · problem during runtimephysicsmaterial

Physics Material 2D change during runtime not taking effect.

Hey, I have this gameObject that changes it PhysicsMaterial2D, on it's CircleCollider2D during runtime, but it is still acting as if it doesn't have the Physics Material. I change it like this:

 var yellowPMat : PhysicsMaterial2D;
 function Update () {
     if (color == 'yellow') {
         gameObject.GetComponent(CircleCollider2D).sharedMaterial = yellowPMat;
     }
     else {
         gameObject.GetComponent(CircleCollider2D).sharedMaterial = null;
     }
 }

I can see in the editor that the material on the CircleCollider2D is changing, but it is not having any effect on the ball's bounciness (the bounciness in the PMat is 0.9) so I don't know what's happening. I feel like I am missing something, so someone help me please. :P Thanks. :D

Comment
Add comment
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

1 Reply

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

Answer by Jtec · Nov 21, 2013 at 03:15 AM

I fixed it myself, but I am still unaware why the issue was occuring in the first place. To fix it I quickly flicked the collider on and off again.

 var yellowPMat : PhysicsMaterial2D;
 
 if (color == 'yellow') {
         gameObject.collider2D.sharedMaterial = yellowPMat;
         gameObject.collider2D.enabled = false;
         gameObject.collider2D.enabled = true;
         
     }
     else {
         gameObject.collider2D.sharedMaterial = null;
         gameObject.collider2D.enabled = false;
         gameObject.collider2D.enabled = true;
     }

So yeah, flicking it off and on again fixed my problem. :P

Comment
Add comment · Show 5 · 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 hamstar · Dec 02, 2013 at 02:13 PM 0
Share

This fix didn't work me unfortunately! Although I'm using EdgeCollider2D(s), not circle colliders. Just so you know, I had the same issue and submitted a bug report which Unity accepted. So you weren't doing anything wrong.

avatar image Jtec · Dec 02, 2013 at 02:36 PM 0
Share

Yeah, I feel like my fix wasn't a REAL fix as such, it just seemed like a dodgy way to get it to work, but it did the job in my case anyway. :P

avatar image hamstar · Dec 03, 2013 at 10:21 AM 1
Share

I must have made a mistake before because I tested it again and it did work (disabling > setting material > enabling). Thanks for the tip.

avatar image LaSuttSutt · Oct 14, 2014 at 08:48 AM 0
Share

It works for that single collider but be careful with other colliders. If you have trigger colliders which collides with that enable/disable collider in this second, the trigger won't work.

avatar image PricklyApps · Nov 27, 2015 at 03:08 AM 0
Share

This is still a problem in Unity 5 and this solution still works.

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

19 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

Related Questions

On carachterspawn level load error? 0 Answers

Save Timer HighScore 1 Answer

Undesired friction when multiple objects are colliding with a rigidbody. 1 Answer

About "Day/Night" little issue 0 Answers

Weird colors on Unity Remote 4 0 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