- Home /
How to create new materials at runtime?
I've read that this is possible, but I haven't been able to figure out how to do it. Can someone explain to me how this works?
I've created a tutorial on YouTube that covers creating a material using a custom image and applying it to a gameObject at run time. Or you can use the Unity documentation :)
Answer by tanoshimi · Sep 13, 2016 at 06:21 AM
Have you read the docs? https://docs.unity3d.com/ScriptReference/Material-ctor.html
There's a constructor where you pass in the shader that should be used by the material. e.g.
Material mat = new Material(Shader.Find("Specular"));
Hi,
I do use this function to create temp mats in making my game. but it looks like it doesn't render in until I click on the material which is attached to the game object I attached it to. I successfully creates the new material as the name appears but the render doesn't happen. Can you be able to help me with this? Also I am using URP.
Your answer
Follow this Question
Related Questions
How do I attach a Created Material A Texture, NormalMap and OcclussionMap? 0 Answers
Multiple materials on one mesh 1 Answer
Changing all materials of selection from code 0 Answers
How to change material that is being scrolled for Material.SetTextureOffset 2 Answers
Scripted SetTextureOffset not working after switching to Universal Render Pipeline 1 Answer