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
0
Question by che1404 · Jan 09, 2015 at 10:07 AM · materialparticleschangedynamicadditive

Cannot dynamically change a material of a SkinnedMeshRenderer

Hi all, I have an animated character in my game that takes a shield component and I'm trying to change from the original material (Mobile/Unlit), to the new shield material (Mobile/Particles/Additive). I'm doing it like this:

 public class MaterialChanger : MonoBehaviour {
 
     public Material shieldMaterial;
     private Material originalMaterial;
 
     void Start () {
         originalMaterial = renderer.material;
     }
     
     void Update () {
         if (Input.anyKeyDown) {
             if (renderer.material == originalMaterial) 
                 renderer.material = shieldMaterial;
             else 
                 renderer.material = originalMaterial;
         }
     }
 }
 

I have isolated the problem into a simple scene, containing my character (with a SkinnedMeshRenderer component), and a simple cube (with a MeshRenderer component), and I have attached the script to both of them.

Well, the material update only works for the cube, but not for the character. The material is stored in an Assets/Materials folder, and I have just dragged it to the script via unity interface.

I don't know what I'm doing wrong, but the truth is that it randomly works in the Editor, sometimes only in Android, and some others only in iOS.

My guess is that there is a fatal combination between SkinnedMeshRenderer and this particular shader (Mobile/Particles/Additive), because changing to a Mobile/Unlit works perfectly.

I have dedicated a lot of hours to this issue, and I'm assuming I won't be able to use this shader in the game. Any ideas? Any other test I could make to discard options? Thanks in advance, Robert.

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
0

Answer by Paulius-Liekis · Jan 09, 2015 at 06:31 PM

Note that renderer.material the first time you call it returns a copy of a material. I'm not entirely sure what happens when you assign renderer.material and then get it again. Try changing it to renderer.sharedMaterial. Anyway, it should not lead to different behaviour on different platforms.

Comment
Add comment · Show 1 · 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 che1404 · Jan 09, 2015 at 06:40 PM 0
Share

Hey, thanks for your time. But it doesn't work. :(

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to change color of Particles/additive material ? 1 Answer

Change material color at runtime!! 5 Answers

Creating a mesh and assigning a material during edit time. 1 Answer

Bullet Texture , Material and Glow Effect : Unity 1 Answer

How to trigger an effect when an object is under a shadow? 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