I tried to remove the code in HideInspectorStuff(), but the bug is still occur.
And I found out how the bug triggers, I don't know if this will help you:
This problem may caused by inspector. When I open STM's inspector, the image is immediately set to HideFlags.HideAndDontSave.
Then if I use the Fix() method you provided earlier, it will be fixed, and later when I open the inspector, bug will not trigger.
BUT, if any of my code changes and a Unity recompile the code, when I open STM's inspector again, the image will be set to DontSave again.
In summary, bugs are triggered when the STM inspector is first time opened after the Unity Editor is opened and code is recompiled, which may be related to some initialization event.
I searched all the code about STM, and there is no code related to hideflag except HideInspectorStuff(), but HideInspectorStuff() is not the cause of the problem, so this may be a bug in the Unity Editor?
That's all I know so far, below is the code I used for the test.
using UnityEngine;
[ExecuteAlways]
public class TestCode : MonoBehaviour
{
[SerializeField] Texture m_texture;
public void Update()
{
if (m_texture.hideFlags == HideFlags.HideAndDontSave) {
Debug.Log("Error");
}
}
[ContextMenu("Fix")]
public void Fix()
{
m_texture.hideFlags = HideFlags.None;
}
}