• 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 CyberGolemn · Mar 30, 2016 at 08:53 AM · alphascript errormeshrendereralpha-channelopacity

Opacity setting from code is not working

I'm an amateur scripter at best so you have my sincerest apologies if there's any novice oversight on my part, but here goes ...

My scene has FX systems comprising of an Empty Parent Object containing four meshes (there are no particles). Each of those meshes are targeting the Particles/Additive (Soft) shader. These polys are also hooked to a script that's scrolling the UV's.

It's all working gangbusters but the systems appearing further off should have some atmospheric perspective. It figures that fading the opacity on these systems would do the job. Easy, right? No! Holy syntax errors Batman! I'm pulling my hair out and kicking furniture trying to get this to happen. Here's the script:

 public float opacity = 1.0f;

 void Start () {
     opacity = gameObject.GetComponent<Renderer>().material.color.a;
 }

Errors are "Material doesn't have a color property '_Color' no matter what shader I select, and the other is a MissingComponetException stating there is no renderer though the Mesh Renderer is right next to it in the Inspector stack. Of course, adjusting the provided opacity setting nets nil.

Any help would be greatly appreciated. Argh! :)

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 RIw · Mar 30, 2016 at 02:28 PM

Try this:

 Color color = GetComponent<MeshRenderer>().material.color;
 color.a = 0.1f;
 //GetComponent<MeshRenderer>().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 CyberGolemn · Mar 30, 2016 at 04:15 PM 0
Share

Thank you Rlw! I don't mean to sound ungracious or be a bother but it's still not having the desired affect (none actually) with the following error in tow:

$$anonymous$$aterial doesn't have a color property '_Color' UnityEngine.$$anonymous$$aterial.get_color()

Obvious guess is that the shader doesn't have ' Color' in it (Subshader>Pass block?). However there should be something in the shader that can be targeted since the texture is being seen ...?? I dug up a similar texture and applied it. Unfortunately the same error and no affect on the opacity persists, but a peek inside the shader shows a $$anonymous$$ainTex. Is this handling the RGBA ins$$anonymous$$d of _Color? If so, is it possible to target it to get the desired opacity control? I've tried several things but nothing's working.

Stranger is that this message persists with nearly every other shader, but on the 'Standard Shader' it doesn't give the error, but it doesn't change the opacity either. Not to mention it plain out looks like butt.

If you have time to respond I'd be grateful. If not it's understandable. In all though, many thanks.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shader question 1 Answer

OnTriggerEnter change alpha to half over time. 3 Answers

How to make this image semi-transparent? 3 Answers

How to make the video background transparent 0 Answers

The Survival Shooter tutorial instructs me to change the alpha value of the Background child of a slider but I don't see an alpha value that I can change. 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