• 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 thi.donada · Mar 04, 2013 at 03:35 PM · runtimetransparency

Transparency not working at runtime

Hello

I want to control the transparency of an object at runtime.

I'm using a simple code to change the alpha channel of the object, but it does not work.

Everything works fine in the editor though, if i change the alpha through the editor it works fine.

Every other answer i found here were about using a Transparent/Diffuse shader and controlling tha alpha using a range from 0 to 1 via code, but i'm using this shader and the correct range already.

Have you ever experiencing anything like this? Thanks in advance.

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

2 Replies

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

Answer by robertbu · Mar 05, 2013 at 05:58 PM

Color is a struct, so you get back a copy of the color, not a reference to it. To fix your problem, you have to assign the color back to the material:

 Color color;
 
 void Start() {
   color = renderer.material.color;
   color.a = 0.5f;
   render.material.color = color;
   }
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 thi.donada · Mar 05, 2013 at 11:57 PM 0
Share

Thanks!!!!!

avatar image
0

Answer by selzero · Mar 04, 2013 at 06:10 PM

Where doesnt it work? The shader that your using may not be compatible with your device.

Comment
Add comment · Show 2 · 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 thi.donada · Mar 05, 2013 at 01:02 PM 0
Share

On my notebook, playing from the editor. What is strange though is that if a tweak the transparency via the editor and then play it works fine, its just from code that it doesn't work. I'm using unity version 3.5.6f4

I guess the simplest code to do it would be:

Color color;

void Start() { color = renderer.material.color; color.a = 0.5f; }

Thanks for replying.

avatar image thi.donada · Mar 05, 2013 at 01:08 PM 0
Share

I did not use color as the name of the variable though as i guess it would not 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Set shader's AlphaCutoff programmatically in HDRP 1 Answer

How to make trees in a terrain transparent in runtime? 0 Answers

INDECIPHERABLE rendering order problem when modifying material property on Runtime 1 Answer

Sprite transparency lost during runtime 0 Answers

Runtime created Material only works when clicking in inspector 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