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 /
  • Help Room /
avatar image
0
Question by AscendReality · Jan 11, 2021 at 02:14 PM · iosalphabuild settings

alpha won't change when built to iOS but works in inspector,alpha doesn't change when built to iOS but works in inspector

Script works fine in the inspector, but when it gets built to iOS, the alpha doesn’t change if the material is initially set as Opaque. All standard shaders in the default render pipeline.

This script is meant to take an object that has more than one material on it and make the GameObject transparent when the slider is used. To ensure that the materials render properly when the alpha is at 1f, I am using a shader utility script to switch the material’s render type to Opaque and switch it to Transparent so that they can fade out.

I want the materials to start as Opaque and only be made Transparent if the slider is used. This is where the script works fine in the inspector, but as soon as I build, the materials won’t change their alpha. I know the script changes them to Transparent, because they render improperly. If I make the materials start off as Transparent, the alpha changes correctly but they again render improperly until I move the slider down then put it back to 1f. So I need the materials to always start as Opaque and only change when the slider gets used.

Why would it suddenly not work when I build to iOS but work in the inspector? Unity 2019.4.3f, AR Foundation 2.1.8, Xcode 12.3, iOS 14.3

 {
 
     public GameObject currentGameObject;
     public Slider slider;
 
     private float alpha = 1f;
     public float Alpha
     {
         get => alpha;
         set
         {
             if (alpha != value)
             {
                 alpha = value;
                 ToggleBlendMode();
                 ChangeAlpha();
             }
         }
     }
     private Renderer[] mRenderers;
     private List<Material> mMaterials = new List<Material>();
 
     void Start()
     {
         // assuming that renderers will be present on currentGameObject at Start and will never change 
         mRenderers = currentGameObject.GetComponentsInChildren<Renderer>();
         foreach (var rend in mRenderers)
         {
             mMaterials.AddRange(rend.materials);
         }
         
         // if slider is present
         if (slider)
         {
             Alpha = slider.value;
             slider.onValueChanged.AddListener((arg) => Alpha = arg);
         }
     }
 
     void ToggleBlendMode()
     {
         foreach (var mat in mMaterials)
         {
             if (Alpha == 1f)
             {
                 //set BlendMode from StandardShaderUtils to Opaque
                 StandardShaderUtils.ChangeRenderMode(mat, StandardShaderUtils.BlendMode.Opaque);
             }
             else if (Alpha < 1f)
             {
                 //set Blendmode to Transparent
                 StandardShaderUtils.ChangeRenderMode(mat, StandardShaderUtils.BlendMode.Transparent);
             }
         }
     }
 
     void ChangeAlpha()
     {
         foreach(var mat in mMaterials)
         {
             Color oldColor = mat.color;
             Color newColor = new Color(oldColor.r, oldColor.g, oldColor.b, Alpha);
             mat.SetColor("_Color", newColor);
         }
     }
 }
 
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 AscendReality · Jan 12, 2021 at 12:19 AM

Found a solution, just use a better transparent shader like the one here, https://docs.unity3d.com/Manual/SL-CullAndDepth.html?_ga=2.55575022.478898987.1610348523-1254744539.1609707651

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

185 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to uinstall IOS support? 0 Answers

How Do I Ensure that --enable-unity-event-support is Set for iOS Builds? 0 Answers

My app is MUCH larger on iOS than Android 1 Answer

How to set Stripping Level for iOS 0 Answers

What is the difference between a Unity Cloud Build and a local build for iOS App Store? 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