Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Shadergui material SetDirty doesnt work

Discussion in 'Scripting' started by xOrfe, Jul 12, 2023.

  1. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    Hello, i am trying to make a toggle for custom shadergui. After changing the material keyword, even if SetDirty is called, the keyword reverts to its old value after saving the scene with Ctrl+S. I tried to do it similar to the documentation, but I couldn't find the source of the problem. Where do you think the problem might be?

    Reference doc : https://docs.unity.cn/ScriptReference/ShaderGUI.html

    Code (CSharp):
    1.  
    2.                     bool toggle = _keywords.Contains(currentFoldoutName);
    3.                     EditorGUI.BeginChangeCheck();
    4.                     toggle = EditorGUILayout.BeginToggleGroup(propertyData.OnlyName, toggle);
    5.                     isInsideFoldout = true;
    6.                     if (EditorGUI.EndChangeCheck())
    7.                     {
    8.                         if (toggle)
    9.                         {
    10.                             _material.EnableKeyword(currentFoldoutName);
    11.                         }
    12.                         else
    13.                         {
    14.                             _material.DisableKeyword(currentFoldoutName);
    15.  
    16.                         }
    17.                         if (!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    18.                         EditorUtility.SetDirty(_material);
    19.                     }
     
  2. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    When i use float instead of boolean keyword, it works well. upload_2023-7-13_1-15-54.png
     

    Attached Files: