Search Unity

Change the Default UI Material?

Discussion in 'UGUI & TextMesh Pro' started by kromenak, Oct 12, 2015.

  1. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    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?
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Not really you could download the source and modify it there but that might be more then you're looking to do.
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    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?
     
  4. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    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;
     
    Last edited: Feb 27, 2018
    yalunar, DanjelRicci, mowax74 and 6 others like this.
  5. as87dgs6asg0a

    as87dgs6asg0a

    Joined:
    Sep 2, 2013
    Posts:
    10
    Oh hello old thread. Is this possible yet?
     
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
    leni8ec likes this.
  7. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51
    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.
     
    rabbitmankind likes this.
  8. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    What is resource checker?
     
  9. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51
  10. Remi_Tribia

    Remi_Tribia

    Joined:
    Apr 29, 2015
    Posts:
    40
    Another solution to know if there are still some remaining gameobjects with default material applied to them is the following :
    1. Create a cube, default-material will be applied to it automatically
    2. Enable Debug Mode in inspector
    3. Find the default-material ID
    4. Use the hierarchy search box and type
      ref:ID:
    It will list all gameobjects using this material.
     
  11. testmaster217

    testmaster217

    Joined:
    Dec 3, 2019
    Posts:
    1
    Does it have to be named "DefaultUIMaterial"? Because I just tried with a different name and I still can't change it.
     
  12. OmarVector

    OmarVector

    Joined:
    Apr 18, 2018
    Posts:
    130
    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?
     
  13. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    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.
     
    Last edited: Sep 13, 2021
  14. WildFlour

    WildFlour

    Joined:
    May 29, 2021
    Posts:
    1
    I guess not. Would love to right click on an object and make it a UI material.
     
  15. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    391
    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.
     
    DwinTeimlon likes this.
  16. Noxury

    Noxury

    Joined:
    Mar 8, 2015
    Posts:
    22
    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. FixUIDefaultShaderReference.png
     
    Last edited: Sep 18, 2021
    unity_QNUSt-4xJRNrXw likes this.
  17. Reahreic

    Reahreic

    Joined:
    Mar 23, 2011
    Posts:
    254
    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.
     
    aliwebconsultant likes this.
  18. aliwebconsultant

    aliwebconsultant

    Joined:
    Sep 8, 2021
    Posts:
    42
    Thanks buddy you are a life savior. I was trying from past 1 hour and just restarting unity solved it
     
  19. samy99

    samy99

    Joined:
    Mar 4, 2020
    Posts:
    9
    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