Material doesn't have a texture property '_MainTex'
UnityEditor.DockArea:OnGUI()
I dug into the Editor logs and the precise message is
[/Applications/buildAgent/work/6bc5f79e0a4296d6/Runtime/Shaders/Material.cpp line 562]
(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Runtime/Shaders/Material.cpp Line: 562)
Material doesn't have a texture property '_MainTex'
UnityEngine.DetailRenderer:Render(Camera, Single, Int32, Single)
UnityEngine.Terrain:CullAllTerrains(Int32)
UnityEditor.Handles:Internal_DrawCameraWithGrid(Camera, Int32, DrawGridParameters&)
UnityEditor.Handles:DrawCameraImpl(Rect, Camera, DrawCameraMode, Boolean, DrawGridParameters, Boolean)
UnityEditor.Handles:DrawCameraStep1(Rect, Camera, DrawCameraMode, DrawGridParameters)
UnityEditor.SceneView:OnGUI()
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
UnityEditor.HostView:Invoke(String, Object)
UnityEditor.HostView:Invoke(String)
UnityEditor.DockArea:OnGUI()
They stop if i delete the terrain, but persist even with a new terrain in a new scene. I'm sure I could work around this, but I'm curious now and want to track down why this is breaking. I have updated the project from pre-Unity3 to the current version, but wasn't getting this error before. Alternatively, does anyone have a way to hone in on materials/prefabs/assets that are causing problems within a project without moving or disrupting the whole project? Can you selectively disable them or something?
if you are using a SRP ( unity shader graph ) , open your graph in its graph window, then add a property with type of Texture2D then name it : “_MainTex” and also name it’s reference to “_MainTex”.
But Important : Remember to uncheck the button called “Exposed”, save your asset and you should be fine. you don’t need to use this new Property
I know this question is really old but I found a way to diagnose this error. You have to find your shader in project tab, select it and in inspector you will see an error. Then you can click “Open compiled shader” and it can give you clues about where the error is. I often mistype things and this helps me find errors.
Its all dependent on the shader you are using. I started with OpenGL ES1.1, then changed to OpenGL2.0. After i switched i noticed i was still getting the error. I had to change the graphics emulation properties under the edit menu to OpenGL ES2.0 and now the problem is gone. Im not sure if its a complete fix or not, but i dont get the error anymore. Hope this helps.
Rebooting my computer usually fixes this error, not sure what causes it but this looks to be a Unity bug (of course this is assuming that you do infact have the _MainTex property defined in your shader as I did).
If your computer crashed, you might want to manually delete the Temp folder from your project to make sure nothing is surviving the restart, maybe forcibly reimporting all assets in your project will be enough to fix this too, I have not tried though.
In my case, I didn’t have a source image set, only the material. Every change to the material would throw this error. I set the source to a dummy image and the error went away.
I get this error every time any scene loads that has sprites used in the UI. I will attach an image to show the setup. As you can see, it shows the image as just red lines, and its just the default setup for using a sprite image. So, the solution of using Unity Shader Gragh dosent solve the error.