Change the Default UI Material?

Is it possible to change the default UI material to use a different shader? Or is the only way to specify an override material for every Graphic in the scene?

I’d like to experiment with adjusting the UI-Default shader, but I can’t find a way to easily apply the modified version of the shader to all UI elements in the scene.

I was hoping there’d be a “Graphic Settings > Default UI Material” field or script call somewhere. Graphic.defaultGraphicMaterial seemed promising, but it’s read only.

So…any good way to do this?

Not really you could download the source and modify it there but that might be more then you’re looking to do.

Sorry to resurrect this thread from the dead, but I’m wondering if changing the default ui is possible yet.
Or would I need to change every graphic to set a material?

Also sorry to resurrect this old thread, but this feature could save me a lot of time. We need to use our custom optimized UI shader for ALL graphic elements in all our scenes and prefabs. Something like the “default physic material” in the Physics settings would be absolutely amazing. If there is not already some way to achieve this.

EDIT: Found a solution - Canvas.GetDefaultCanvasMaterial().shader = _defaultGUIShader;

9 Likes

Oh hello old thread. Is this possible yet?

As a setting in the UI of the Editor no. But has Gorren said, you can do Canvas.GetDefaultCanvasMaterial() = myNewMaterial and that will assign it back to the one you set. A simple script that has that line in Start() should work until we find a way to have a preset.

1 Like

Here’s how I did it to make it future proof.

  1. Create a new material and name it “DefaultUIMaterial”. (Optionally create a FastUIMaterial with your other UI shader)
  2. Open Resource Checker
  3. Select all UI elements using Resource Checker. (Click the relevant button to select the relevant gameojbects)
  4. Since it auto selects all elements in the active scene you can change any property. (Thanks to the Multi Edit feature for certain components)
  5. Drag and drop the “DefaultUIMaterial” to all the UIElements you care about. A single change will effect 1000’s of elements on your scene so make sure you check in your code before you make this change.
    Done.

If you need certain elements to have a different material just repeat the above steps and use your other material.

1 Like

What is resource checker?

resource checker is a Unity Asset that helps identify all used resources in the scene or project
https://assetstore.unity.com/packages/tools/utilities/resource-checker-3224

Another solution to know if there are still some remaining gameobjects with default material applied to them is the following :

  • Create a cube, default-material will be applied to it automatically
  • Enable Debug Mode in inspector
  • Find the default-material ID
  • Use the hierarchy search box and type ref:ID:

It will list all gameobjects using this material.

Does it have to be named “DefaultUIMaterial”? Because I just tried with a different name and I still can’t change it.

I found adding new material to Images that share the same attlas, break down the Drawcall batching.

Does anyone know how after changing the material, the draw call remain the same while using unity atlas?

Is there still no decent solution for this problem?
This is especially problematic as the current default UI shader does not work correctly with linear color space.

I guess not. Would love to right click on an object and make it a UI material.

You can replace “UI/Default” in the Graphics Settings’s Always Included Shaders with a custom shader(the name should be “UI/Default”) in your project. It works in 2019.4.29f1, but I’m not sure whether it works in other versions.

1 Like

Place the shader to the resource folder and name it “UI-Default”. The BuiltIn Material with that name replaces its shader with the previously mentioned one. This works also for other BuiltIn-Materials.

But I found no way to reverse that action without downloading the original shaders to replace again. It is also redundant since the builtInShaders are always in the projects.

How can I reset the shader reference of the builtIn default Material back to the built In shader? I Can’t change it in DebugMode since the variable is private and the inspector doesnt allow it to change. Calling Reset from the context menu does nothing.

1 Like

Just an FYI, I tried this with 2022.1.16f1 and it didn’t work, until after restarting Unity.

That said, thank you so much. this saved me having to manually apply an override material to every UI element to address URP single pass instanced world space UI issues.

1 Like

Thanks buddy you are a life savior. I was trying from past 1 hour and just restarting unity solved it

It only work on editor mode, if build to app,it not work,all the ui material ref the default shader from unity build-in,not ref my custom UI.default shader

I dont know if its a bug or not but creating a shader called “UI/Default” will override the default UI. Learnt this the hard way :grin: