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
5
Question by huhund · Mar 10, 2015 at 09:59 AM · uiimagesetfloat

How can I change the shader parameters for an UI Image?

How can I change the shader parameters for an UI Image?

—

So, inside a canvas I have an image. I have written a custom shader for it and I want to set a shader parameter using SetFloat().

I’m trying this:

myImage.materail.SetFloat( “Param”, 1f );

But the setting the parameter will access the global material, thus affecting all images. I want to access the instance material for the image so that I change only that single image. How can I do this?

—

Footnote: I do know how to do this for meshes. There I access the material for the renderer component and it works. But for UI Images this there is no render compenent.

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
18

Answer by Matkins · Mar 10, 2015 at 08:15 PM

I just ran into the same problem. I solved it like this:

 Material mat = Instantiate(image.material);
 mat.SetFloat("_SomeProperty", 1f);
 image.material = mat;
Comment
Add comment · Show 8 · 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 huhund · Mar 12, 2015 at 07:19 AM 0
Share

Cheers, it worked, thanks!

avatar image VamossVoar · Feb 10, 2016 at 09:52 PM 0
Share

You saved me a lot of work! Thankssss!!!!!

avatar image bobmoff · Mar 18, 2016 at 08:45 AM 0
Share

Thanks for sorting this out. Wonder why Unity does these kind of things. What is the reason for making the Image not behave like other entities with materials.

avatar image Superrodan · Feb 01, 2018 at 10:55 AM 2
Share

I wish there was some way to get google to move this up in the results when I searched for material instance problems. Nearly every other response seemed to assume that all materials worked the same as mesh render materials. This fixed my problem instantly, thanks!

avatar image Dschella · Feb 04, 2019 at 01:14 AM 0
Share

godly answer! thanks

Show more comments
avatar image
-1

Answer by boylec · Jun 02, 2015 at 08:37 AM

The following is true for all renderers I have worked with, I'm assuming it is true for UI.Image components as well (Unity GUI images): Just use the renderer.material of the object. Renderer.sharedMaterial is the global one, but as soon as you access the renderer.material Unity makes the material it's own instance.

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

12 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

Related Questions

Image on game object is not being rendered 1 Answer

How do you automatically fit a child of a layout group to the parent without it adjusting to fit its own contents? 1 Answer

RenderTexture does not render canvas image. 0 Answers

UI Escape menu script not working. 2 Answers

UI Layering Problem! 2 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