Can a Unity script edit the name of a material?

Is there any scripting that allows for a material’s name to be edited?
I don’t mean that a material can be switched or replaced with a different material. Rather, the same material’s name will be changed to a new name but is the same material.

This functionality would be useful for a script who’s purpose is to create prefabs of assets to meet certain requirements, such as that the material name should be the same as the object they are attached to.

In runtime doing renderer.material.name = newName; should work, because that return a copy of a material.

In editor to have a different name you will have to duplicate the material asset and then renamed it and assign to your renderer.