Search Unity

Question Destroyed all Shaders, Please help

Discussion in 'Shaders' started by Unifikation, Jan 29, 2023.

  1. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    I did this, and it destroyed all the shaders. They now show nothing, at all.

      string disastrous = TMPro.ShaderUtilities.Keyword_Glow;


    How do I undo whatever this has changed in all the shaders?

    This was the error:

    Code (Boo):
    1. UnityException: Find is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'TMP_ColorControl'.
    2. See "Script Serialization" page in the Unity Manual for further details.
    3. TMPro.ShaderUtilities.GetShaderPropertyIDs () (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Runtime/TMP_ShaderUtilities.cs:216)
    4. TMPro.ShaderUtilities..cctor () (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Runtime/TMP_ShaderUtilities.cs:132)
    5. Rethrow as TypeInitializationException: The type initializer for 'TMPro.ShaderUtilities' threw an exception.
    6. TMPro.EditorUtilities.TMP_SDFShaderGUI.DoFacePanel () (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Editor/TMP_SDFShaderGUI.cs:198)
    7. TMPro.EditorUtilities.TMP_SDFShaderGUI.DoGUI () (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Editor/TMP_SDFShaderGUI.cs:64)
    8. TMPro.EditorUtilities.TMP_BaseShaderGUI.OnGUI (UnityEditor.MaterialEditor materialEditor, UnityEditor.MaterialProperty[] properties) (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Editor/TMP_BaseShaderGUI.cs:163)
    9. UnityEditor.MaterialEditor.PropertiesGUI () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:1724)
    10. UnityEditor.MaterialEditor.OnInspectorGUI () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:477)
    11. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:527)
    12. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)
    13.  
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Is your TMP_ColorControl script custom made?
    It did a Find operation during compilation which likely just broke the compilation pipeline so your shaders merely aren't compiled right now. They're not "destroyed".

    If it's a custom script, move the code from the constructor to Start() if possible. Otherwise if it's not custom, you might just need to update the TMP package from your package manager.
     
    Unifikation likes this.
  3. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    Yes, TMP_ColorControl is a custom script. Sorry, should have named this something more obviously NOT of Unity origin.

    THANK YOU for the relief. I'd lost a lot of work... I thought. About a day's creativity just blew up... which doesn't sound like much, but it was creativity, there was no certainty I could repeat it.

    Having removed this line, entirely, and then Refreshed everything, then restarting Unity, then making another code change (of no consequence, just to force another Refresh) and then deleting and reimporting a single shader... and then restarting Unity again... and then doing another wacky Refresh... then one more restart of Unity... DADA!!!

    They're back!

    THANK YOU!!!!

    Will use the string to int, from now on, and try to ensure this little heart failure event never happens again.

    For those wondering, I think this is better than the above:

        static readonly int GlowColor = Shader.PropertyToID( "_GlowColor" );


    And here's a fully operational glow colour cycler.... if you make the gradient and pick a text object yourself:

    Code (CSharp):
    1.  
    2. using TMPro;
    3. using UnityEngine;
    4.  
    5. public class TMP_GlowColorControl : MonoBehaviour {
    6.  
    7.     [GradientUsage(true)] // ensures HDR gradient - important for glows
    8.     public Gradient colors; // edit in Editor to have a cool gradient
    9.     static readonly int GlowColor = Shader.PropertyToID( "_GlowColor" );
    10.     public float rate = 2.0f; // changes rate of gradient cycling
    11.     float _c; // cycle stage, of gradient - oscillates between 0 & 1
    12.  
    13.     public Material myFontMaterial; // is only public to ensure working
    14.     public TextMeshPro myTexmMeshPro;
    15.  
    16.     void Start ( ) {
    17.         myFontMaterial = myTexmMeshPro.fontSharedMaterial;
    18.     }
    19.  
    20.     void Update ( ) {
    21.         myFontMaterial.SetColor( GlowColor, colors.Evaluate( _c ) );
    22.         _c = Mathf.PingPong( Time.realtimeSinceStartup * rate, 1 );
    23.     }
    24. }
    25.  
     
    Last edited: Jan 30, 2023
    Invertex likes this.