Swap every material/shader with a another material/shader

Hello there,
I would like to find a way to change every GameObject’s material (or just the shader assigned to the material) to a specific one.
For example, let’s say that I have 50 objects and all of them have a unique different material(with a different shader as well).
I would like to basically press a custom made button in the editor and force every GameObject to use another shader (all of the objects will use the same material/shader at this point).
Also I would like to avoid shader replacement so I don’t have to modify anything in the existing shaders.
Additionally, I can potentially add more custom buttons to the editor to test, for example, different shaders/materials on all the GameObjects at once.
Thank you.

For your hotkey, you’re going to want to read the MenuItem manual page.

You can use FindObjectsOfType to find all scene objects of a particular type (such as GameObject, or Renderer).

Each renderer has an array of materials. While the game is running, you’ll usually want to edit the materials array; if you’re editing a scene file, you’ll usually want to edit the sharedMaterials array; the reason for this should be apparent if you read both of the linked manual pages.

Finally, each material has a shader reference which you can set. It’s easy enough to look one up by name with Shader.Find.

If there are many objects in your scene, it may be handy to look into supporting the Undo class and/or displaying a progress bar.