Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 janidsa · Aug 17, 2015 at 05:44 PM · alphabug-perhapscutoutcutoff

Adjusting alpha cutoff during run time doesn't work

Hello, I am trying to change the render mode of my material on a standard shader to cutout mode with the following code:

 mesh_renderer.materials[0].SetFloat("_Mode", 1);
 mesh_renderer.materials[0].SetFloat("_Cutoff", 1f);

alt text

The code works just fine and the alpha cutoff is set correctly in the inspector, however it doesn't work on the mesh until I drag it to any other value than 1f, and then back to 1f in the inspector, even if I ran the code through update.

Is there a way it would apply the changes to the material from the code, without requiring me to manually do that?

Thanks in advance!

Comment
Add comment · Show 1
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 jmgek · Aug 17, 2015 at 05:51 PM 0
Share

Try setting cutoff to 0 then 1

1 Reply

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

Answer by Thomas-Mountainborn · Aug 17, 2015 at 06:09 PM

A material created at runtime does not have all the necessary standard shader keywords enabled. You need to set a bunch of other ones before you have it set as transparent - by dragging the value in the inspector, the editor does this for you, which is why that works.

 material.SetOverrideTag("RenderType", "TransparentCutout");
 material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
 material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
 material.SetInt("_ZWrite", 1);
 material.EnableKeyword("_ALPHATEST_ON");
 material.DisableKeyword("_ALPHABLEND_ON");
 material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
 material.renderQueue = 2450;

This post by Farfarer provides a handy method to make your life easier in regards to this issue.

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 janidsa · Aug 17, 2015 at 06:58 PM 1
Share

Thank you! This solved the issue.

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

Is there a way to cast (maybe recieve) sprite shadows without discarding alpha pixels with cutout shader? 0 Answers

Video player component with cutout or alpha texture in material 0 Answers

Set Alpha cutoff Unity3d 1 Answer

Transparent cutout shader for circular timer from Photoshop PNG is too messy/sloppy 1 Answer

Do alpha cut off with seperate texture? 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