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 CG-DJ · Apr 25, 2014 at 08:37 PM · shaderoutlinetoonchange colorsetcolor

Set Color not working on Outline

Hey Guys,

I'm trying to change the outline color of a shader based on the characters health. So when the character has high health, his outline is green, but as it gets closer to 0, it turns more and more red.

My problem is I can't seem to find a way to change the color of the outline. I think I need to use "Material.SetColor", but it's not effecting the outline color at all. Here is the line I'm trying to use (c#):

 thisRenderer.material.SetColor("_OutlineColor", Color.red);

I'm just using a Color.Lerp based on the character's health to switch between the colors for low and high health. The name of the property in the shader file is "_OutlineColor", so that's what I need to change, right?

To test this, I make the material's color outside of play mode cyan. Then I put this line of code inside the Update function. So what should happen is the character's color will change to red every frame. However, when I go into play mode, the character's color stays cyan. What's happening?

Thanks for the help. (Shader file here: http://wiki.unity3d.com/index.php?title=Silhouette-Outlined_Diffuse)

Comment
Add comment · Show 10
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 robertbu · Apr 25, 2014 at 09:31 PM 0
Share

Your code works for me. I used:

 function Start() {
     renderer.material.SetColor("_OutlineColor", Color.blue);
 }

...with the shader you specified, and the color changed. Are you sure that 'thisRenderer' points to the renderer with a material that has the outline shader?

avatar image Cherno · Apr 26, 2014 at 02:20 AM 0
Share

renderer.material only works if the renderer has only one material, otherwise you have to use renderer.materials and iterate through each one. Also, check that _Outlinecolor is indeed the right name of the color variable in the shader script.

avatar image CG-DJ · Apr 26, 2014 at 06:49 AM 0
Share

I'm pretty sure thisRenderer is right. I use it other places to change the material. I can change from a diffuse to an outline diffuse, but it won't let me change color.

And I'm pretty sure "_OutlineColor" is the right variable name. What else could it be.

avatar image robertbu · Apr 26, 2014 at 07:16 AM 0
Share

I'd do a test scene with a cube, a material with this shader, and my short script. Works or not, it will tell you something. Also did you read @Cherno's comment? If your object has multiple materials, then you need to cycle through all the materials in the materials array, not just 'material'.

avatar image CG-DJ · Apr 29, 2014 at 03:16 AM 0
Share

thisRenderer only has one material. I change the material manually through scripting.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

Shader Assitance: Sprite Outline Color, Hidden Object -1 Answers

Modified Toon Shader: scaled instead of projected (how to?) 0 Answers

Ztest shader issues 0 Answers

Outline diffuse shader (toon) : no results? 1 Answer

Better Outlines 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