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 Sprakle · Mar 25, 2015 at 11:20 PM · unity 5materialtransparency

Material alpha not updating at runtime

I'm attempting to clone a material and apply it to an object at runtime. All properties seem to carry over, but for some reason the transparency stops working.

Script:

 using UnityEngine;
 
 public class MaterialApply : MonoBehaviour
 {
     public Material copyMaterial;
 
     private void Start ()
     {
         Material newMaterial = new Material(copyMaterial);
         GetComponent<MeshRenderer>().material = newMaterial;
     }
 }


On the left is an object with the material applied inside the editor. You can see the transparency working fine. On the right is a blank cube that the material will be copied to at runtime:

alt text

Here is the result after the material is copied at runtime:

alt text

You can see the material sort of copied over, but the object is opaque.

If I select the target cube, you can see all the properties are there, including alpha: alt text

Any idea why this is happening? I suspect there is just some UpdateMaterialType() or similar function I need to call somewhere.

Comment
Add comment · Show 7
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 maccabbe · Mar 25, 2015 at 11:50 PM 0
Share

There is a method, $$anonymous$$aterial.CopyPropertiesFrom$$anonymous$$aterial($$anonymous$$aterial mat) that you can try. http://docs.unity3d.com/ScriptReference/$$anonymous$$aterial.CopyPropertiesFrom$$anonymous$$aterial.html

However I can't replicate the error as duplicating a material should also automatically duplicate all the properties. When you use Debug.Log(copy$$anonymous$$aterial.property) and Debug.Log(new$$anonymous$$aterial.property) are the values different?

avatar image Sprakle · Mar 26, 2015 at 12:22 AM 0
Share

@maccabbe

CopyPropertiesFrom$$anonymous$$aterial has the same result. And yeah, I get the same properties from logging.

Here's a super quick example project with the problem: http://dropcanvas.com/y5c6x

You can see it by opening the Test Scene and hitting play.

avatar image Glurth · Mar 26, 2015 at 01:22 AM 0
Share

downloaded project, but scene has no objects oh, perhaps you are using pro version and I'm not?

avatar image Sprakle · Mar 26, 2015 at 01:26 AM 0
Share

@glurth

I downloaded my file to confirm, there's definitely stuff in the scene. (Looks like I typod the name though, it's "Text Scene" that you should open)

This is a Unity 5 project btw. You wont be able to open it in an old version.

avatar image fredlllll · Mar 26, 2015 at 03:34 AM 0
Share

does it work when you use Instantiate<$$anonymous$$aterial>(...) ins$$anonymous$$d of new $$anonymous$$aterial(...)?

Show more comments

1 Reply

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

Answer by fredlllll · Mar 26, 2015 at 05:14 AM

Use Instantiate<Material>(...) instead of new Material(...)

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

22 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

Related Questions

Applying partly transparent texture to a 3d model made in Blender. 1 Answer

Shader that makes object transparent as light hits it 0 Answers

Edge Detection (effect normals) with water (transparent) error. 0 Answers

Transparent material on iPhone Android 3 Answers

How do you make an X-ray vision following the mouse? 1 Answer


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