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 CThayer · Oct 11, 2020 at 12:44 AM · shadermaterialshadersmaterials

Why do materials created at runtime show up incorrectly in the inspector?

Hi Everyone,


I have been searching everywhere for a solution for this but I just can't seem to find it. Basically, I am creating a material at runtime that is a copy of an existing material. Then I assign it to a GameObject and it appears correctly from a graphics point of view, BUT, the details for the new material are not available in the inspector.


Is this just an inherent limitation with the editor / materials? Or is there some sort of flag that I need to set in order for a runtime material to become visible?


Here is a screenshot of what it shows in the editor: alt text


And here is a very simple script that you can use to see what I am talking about:

 public class SimpleMatCopy : MonoBehaviour
 {
     public GameObject ObjA;
     public GameObject ObjB;
     
     // Start is called before the first frame update
     void Start()
     {
         Material mat = new Material(ObjA.GetComponent<Renderer>().material);
         mat.CopyPropertiesFromMaterial(ObjA.GetComponent<Renderer>().material);
         mat.name = "ObjB_mat";
         ObjB.GetComponent<Renderer>().material = mat;
     }
 }

(Just assign GameObjects to ObjA and ObjB and make sure that they have different materials applied to them before running.)


I have also tried using:

 Material mat = new Material(Shader.Find("Standard"));

but I got the same results.

I vaguely remember reading somewhere that you have to use Shader.EnableKeyword() in certain situations to get some of the properties to appear correctly but I tried all the standard shader's keywords and it didn't seem to have any impact on my issue. That being said, I might have done it wrong.


Thank you in advance for any help/ clarifications you can provide.

no-shader-selected.png (126.6 kB)
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 GioVill · Mar 17, 2021 at 05:02 PM 0
Share

I have the same inspector bug. I have a custom shader made from the shader graph and when I assign a material with it at runtime the problem appears. I have to read the properties by using the inspector debug mode but it's insane. Anyone have a solution?

avatar image CThayer · Mar 29, 2021 at 09:59 PM 0
Share

Sorry I didn't reply to you sooner but, unfortunately, I never found a solution or even any additional information. As far as I can tell, this is either a bug with the inspector or a seriously inconvenient expected behavior. It is extremely annoying for anyone working with materials at runtime. For example, procedural materials or procedurally generated copies/variants are basically impossible to inspect which makes it super challenging to fine tune them or troubleshoot issues. For that matter, any material that I create from script can't be inspected (even if it just creates a copy of an existing one).


If anyone ever finds a solution to this (or even just more information) I would be THRILLED!


Alternatively, I am considering writing a custom inspector to solve this because it is such a pain. I just don't want to bother writing one if there is an existing solution that I don't know about.

avatar image andrew-lukasik · Mar 29, 2021 at 11:11 PM 0
Share

Double click on material field for that Renderer component. This selects the material and thus shows it's inspector.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Terraya · Mar 30, 2021 at 02:32 AM

So out of the Box i would assume that happens because you got "No Shader selected" i assume you already notice that as well,

you will need to assign a "Shader" to your Material, you will also need to have the "Renderer" declared as variable,

take a look here at the wiki: Unity Wiki

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

234 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamic batching breaks with the material Mobile/Alpha Blended. 0 Answers

Is this the correct way? 1 Answer

MaterialPropertyBlock causes Z-fighting sprites 0 Answers

How to apply a color to the second texture in this shader? 1 Answer

How to make a cube with metallic look and soft edges [pic included] 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