• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
4
Question by Garitzar · Apr 10, 2014 at 09:23 AM · shadermaterial color

Change Shader Property at runtime

Hello community. Have a object with "Toon/Basic Outline" Shader.

The properties of this shader is

 Properties {
         _OutlineColor ("Outline Color", Color) = (0,0,0,1)
     }

And in my script I want to change the "Outline Color" property at runtime.

I have tried:

 renderer.material.setColor("Outline Color", Color.red);

But I cannot get it to change.

[SOLVED] Solution was to write _OutlineColor and not "Outling Color". I also discovered that I could not use my own Color ( example: new Color(1,1,1,1)), I had to use build in colors( example: Color.red)

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
16

Answer by Berenger · Apr 10, 2014 at 09:26 AM

First parameter is the name of the variable, not the label .

 renderer.material.setColor("_OutlineColor", Color.red);



These days in Unity:

 gameObject.GetComponent<Renderer>().sharedMaterial.SetFloat("_YourParameter", someValue);



Comment
Add comment · Show 2 · 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 Garitzar · Apr 10, 2014 at 01:26 PM -1
Share

Thank you. Do you know if I can make my own Color ins$$anonymous$$d of using Color.someColor?

avatar image sh_code Garitzar · Jan 13, 2019 at 10:54 PM 0
Share

new Color(r, g, b, a)

avatar image
3

Answer by Shivam_Dhoot · Oct 01, 2014 at 05:57 AM

 `renderer.material.setColor("_OutlineColor",new Vector4(a,b,c,d));`

a,b,c,d will be red,green,blue and alpha values for your color.



These days in Unity:

 gameObject.GetComponent<Renderer>().sharedMaterial.SetFloat("_YourParameter", someValue);



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 udk_lethal_d0se · Oct 28, 2015 at 07:10 PM 1
Share

You can also use the following ins$$anonymous$$d of a Vector4.

 new Color32(127, 127, 127, 255)

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

28 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

Related Questions

Using Color.Lerp with Lightweight Render Pipeline 1 Answer

Simple Color Shader for 3D Models 0 Answers

Colors does not aplying to particle system with mesh render mode + material with standard shader. 2 Answers

Can anyone solve this?Build/Material/Shader/Android/Quality 0 Answers

How Do I Partially Change The Material of An Object On Collision? 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