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 tanoshimi · Sep 11, 2013 at 02:02 PM · androidshadermaterial

Material SetColor in a loop not working on Android

Ok, so I'm being blinded by something obvious here, so I'm really hoping a fresh pair of eyes can help me out!

I have a custom shader with a _ColourBoost Color property as follows:

 Shader "CameraFeed" {
     Properties {
         ...
         _ColourBoost ("Colour Boost", Color) = (0.2,0.4,0.2,1.0)
         ...

I can set that property in the material from a C# script, and it works as you'd expect when run in both the editor and on the Android device I'm targetting:

 CameraMaterial.SetColor("_ColourBoost", new Color(0.39F,0.5F,0.39F));

But, if i try to update that value in a loop (e.g. a fade starting from black and ending at the chosen colour), something like this:

 private float progress = 0.0f;
 while(progress<1) {
   CameraMaterial.SetColor("_ColourBoost", new Color(0.39F*progress,0.5F*progress,0.39F*progress));
   progress += Time.deltaTime/6; // Fade in over 6 seconds
 }

If I play in the editor, it appears as I expect - fading the colour in from black over 6 seconds. But when deployed to my Android device, it apparently does nothing - the material doesn't change and remains exactly the same over the course of the loop.

If it makes a difference, the loop is contained in an OnGUI function, but what I really don't understand is why the behaviour in the editor doesn't match that on the device. Any ideas what I'm missing here? Thanks!

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
Best Answer

Answer by tanoshimi · Sep 11, 2013 at 02:53 PM

Solved it (although I don't quite understand how/why). A separate script was responsible for setting the _MainTex property on this same material, as follows:

 renderer.material.SetTexture("_MainTex", cameraTexture);

changing this to:

 renderer.sharedMaterial.SetTexture("_MainTex", cameraTexture);

fixed the issue. Strange.

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

15 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

Related Questions

Transparency working in the editor but not when I build 0 Answers

Shader/Material not displaying properly when attached model loaded from bundle 0 Answers

Black Material if Use Mip level?!! 0 Answers

Transparent material on iPhone Android 3 Answers

How to use 3rd Party Shader with LWRP / URP 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