Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 libufan · Dec 06, 2016 at 01:39 PM · shaderrefresh

Shader can be set to refresh it?

alt text I have a question about shader. i used the lab renderer in my project.

if i choose unit by mouse click, the gameobjects effect in game window will be changed immediately. but when i change it by code, the value is changed, But the effect did not change.

If I choose this object again, and the main points open shader detailed list, the effect will be changed, can anybody told me why? Why the use code to control effect will not change immediately?

if i change the texture by code , the effect will chane immediately! alt text

thanks for help me

normal.jpg (9.8 kB)
detail.jpg (13.2 kB)
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
0

Answer by AlwaysSunny · Dec 06, 2016 at 01:38 PM

Thank you for including screenshots. Your situation is not 100% clear. Try to use your strongest English skills when posting.

It sounds like you might be discovering the difference between a material in your project's assets and an instance of that material. In most cases, materials get instantiated when you change them with code. Each object which changes its material with code gets its own instance of that material that lives in memory, and gets destroyed when exiting play mode.

http://answers.unity3d.com/questions/228744/material-versus-shared-material.html http://answers.unity3d.com/questions/684089/change-shader-property-at-runtime-1.html

To address ALL instances of a material, when you cannot use the sharedMaterial, you'll need a reference to every object using the original material. You can then address each instance of that material (on each object individually) to make your changes one by one.

 foreach (GameObject go in myCollectionOfGameObjects) {
     go.renderer.material.SetProperty("unlit", true);
 }

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 libufan · Dec 08, 2016 at 08:25 AM 0
Share

Thank you for reply.This is the way I used to be. alt text

I found that the unlit attribute is not the same as that of the other attributes.so change _Color can be. not the g_bUnlit. why? alt text

code1.jpg (10.9 kB)
code.jpg (19.6 kB)
avatar image AlwaysSunny libufan · Dec 08, 2016 at 08:27 AM 0
Share

Please never share screenshots of code. Always paste and format code with 101010 button ins$$anonymous$$d.
And please post comments as comments and not answers (converted).

Looks like it's an integer value, I didn't realize that. Have you tried this:

 material.SetInt("g_bUnlit", 1);

In other words, not checking for the property, but just calling it without checking?

avatar image
0

Answer by libufan · Dec 08, 2016 at 12:31 PM

when i called this,

 material.SetInt("g_bUnlit", 1);

it will be checking, but the effect not changed. i must to choose the material, then effect will be changed immediately.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Shader not refreshing after changes 0 Answers

Making shader's first pass light sensitive (2D) 0 Answers

Shaders - changing the vertex color via script 1 Answer

How to change when a halo is drawn? 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