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
1
Question by VivienS · Feb 19, 2011 at 01:59 PM · materialvariablesplayrenderqueue

How to permanently set the renderQueue variable for a material?

Hello!

Is there a way to set the render queue integer of a material (Geometry, Transparent, Overlay, etc), so that it stays this way after I hit stop again?

I want to stop using the shader's render queue for every tiny bit of geometry that needs to render before or after something. So I've tried this script:

void Start () {
  renderer.material.renderQueue = 1234; // some render queue integer
}

or

void Start () {
  renderer.sharedMaterial.renderQueue = 1234; // some render queue integer
}

which works great but (not surprisingly) resets every time I stop the playback. Is there a way to modify the material itself so that I could re-use it in other scenes as well, without having to use the script all the time?

Thank you!

Comment
Add comment · Show 3
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 yoyo · Mar 14, 2011 at 05:53 PM 0
Share

I've tried setting it from a custom editor, because I want the layering to work in the scene view as well as during gameplay. It works when I set it, but again, doesn't seem to remember its value -- when I start Unity and load the scene, or even after running the game and pressing stop, it resets back to whatever default it had originally.

avatar image yoyo · Mar 14, 2011 at 06:38 PM 0
Share

I just did a little experiment that seems to work -- I initialize the render queue when the editor starts up, and when the game stops playing. I'm doing this with the EditorApplication.update and EditorApplication.playmodeStateChanged callbacks.

avatar image yoyo · Mar 14, 2011 at 06:47 PM 0
Share

P.S. After setting the render queue I call the undocumented method SceneView.RepaintAll() to update the scene view.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jessy · Feb 19, 2011 at 03:44 PM

Not that I know of. The only way I think you can do this is to copy the shader over and over again, using a different hardcoded Queue tag for each one.

(And for me, the value persists after I get out of Play mode, but is not persistent if I quit Unity and then reopen it.)

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 VivienS · Feb 19, 2011 at 05:39 PM 0
Share

Hardcoding it was what I did up until now. I have about 10 different shaders now with basically the same code, only a different render queue tag -> not really ideal atm.

But well, guess there's no way around it then. THAN$$anonymous$$S!

avatar image
2

Answer by Wolfram · Sep 17, 2015 at 05:54 PM

Yes, there is a way. I just discovered it due to a Unity bug... -.-

In Unity5, Unity introduced the "Standard" shader. Accompanying that shader is the "StandardShaderGUI.cs" Editor script, which does (amongst other things) exactly what you want.

In fact, it does it so perfectly well, that you can permanently change your Material's render queue, and never be able to reset it, no matter which shader you are assigning... -.-

As proof, reproduce the Unity bug I mentioned:

  • Set the Standard shader's RenderingMode of any Material in the Inspector to any value other than "Opaque", for example to "Cutout".

  • Switch the inspector to "Debug" mode. Notice the value "Custom Render Queue" being 2450 (=the internal default queue for cutout shaders).

  • Switch back to "Normal" mode. Assign ANY shader that is not a "Standard" shader to your material.

  • Switch back to "Debug" mode. Notice the value is STILL 2450, and if you create a test scene you will notice this really is the queue value your shader uses now.

  • The only way to RESET this hidden m_CustomRenderQueue material property is to once again assign the "Standard" shader, and switch that back to "Opaque". This will set m_CustomRenderQueue to -1, which means the vlaue is ignored, and the actual queue value defined in the shader is used again.

=> So you should be able to somehow modify Unity's "StandardShaderGUI.cs" script to just set your custom shader queue value - keeping in mind that this value will permanently ovveride all subsequent shader changes to that material, unless you reset it to -1.

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

1 Person is following this question.

avatar image

Related Questions

Material Lerp Var not working 1 Answer

Sprite behind semi transparent mesh 0 Answers

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Error BCE0019: 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