Stencil overwrites mark scene dirty on load
I had the problem for quite some time now, that my scenes always got dirty as soon as I opened them. I finally took the time to take a look what is causing it: The stencil overwrite on any shapes component auto-changes the scene at every opening.
This alone will mark the scene dirty every time it is opened. This is especially annoying when using a vcs. Only the file id and position in the .unity yaml file is changing.
Also happens for me for the gallery scene.
HelIo,
I was facing a similar issue where I work. The scene would get dirtied everytime we would run the scene in the editor. I "fixed" it in a way with the following solution:
I added the following to ShapesRenderer.cs:
```csharp
[SerializeField]
bool shouldUpdateMaterialPropertiesInEditor = false;
public bool ShouldUpdateMaterialPropertiesInEditor {
get => shouldUpdateMaterialPropertiesInEditor;
set => shouldUpdateMaterialPropertiesInEditor = value;
}
private protected void UpdateMaterial() {
#if UNITY_EDITOR
if (IsUsingUniqueMaterials && !UnityEditor.EditorApplication.isPlaying &&
!shouldUpdateMaterialPropertiesInEditor)
return;
#endif
// ...
}
internal void UpdateAllMaterialProperties()
{
#if UNITY_EDITOR
if (IsUsingUniqueMaterials && !UnityEditor.EditorApplication.isPlaying &&
!shouldUpdateMaterialPropertiesInEditor)
return;
#endif
// ...
}
```
I also modified ShapesRendererEditor.cs with the following:
```csharp
SerializedProperty propShouldUpdateMaterialPropertiesInEditor = null;
protected void BeginProperties( bool showColor = true, bool canEditDetailLevel = true )
{
// ...
if( uniqueCount > 0 ) {
using (ShapesUI.Horizontal)
{
GUIContent icon = EditorGUIUtility.IconContent("console.warnicon.sml");
GUILayout.Label(icon);
string note = "Note: Current configuration will cause scene to be dirtied when entering and exiting
play mode. " +
"For now, the fix is to toggle off shapes material updates in edit mode. Use the button on the right to " +
"toggle it on for previewing while designing but don't forget to turn it off when done.";
GUILayout.TextArea(note, wrapLabel);
ShapeRenderer shapeRenderer = target as ShapeRenderer;
string onOff = shapeRenderer.ShouldUpdateMaterialPropertiesInEditor ? "ON" : "OFF";
if (GUILayout.Button(onOff, EditorStyles.miniButton))
{
if (shapeRenderer.ShouldUpdateMaterialPropertiesInEditor)
propShouldUpdateMaterialPropertiesInEditor.boolValue = false;
else
propShouldUpdateMaterialPropertiesInEditor.boolValue = true;
}
}
//...
}
```
Example in editor:
Hopefully this helps someone else.
Regards,
Daniel
Just wanted to +1 this issue. Also wanted to say @ daniel, wow! Your workaround is great, thank you.
In my case, I used your code workaround to set shapes with custom sorting and depth settings (setting stuff to OFF). In case anybody else is still getting dirty scene issues: For whatever reason I also had to go over objects with default settings- set them their sorting & depth to something random, and then reset them back to default. Doing both now gives me a clean scene.