Getting [Error] Destroying assets is not permitted to avoid data loss in Unity 6 / Shapes 4.5.0 in the Editor
Hi when I play my scene in the Unity 6 editor (with Shapes 4.5.0), I am getting the following error when I stop the scene. This didn't happen previously when I was on Unity 2022.3.x and Shapes 4.3.x. This can be reproduced by opening the Shapes Gallery sample scene.
[Error] Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
Object.Destroy()
ShapesExtensions.TryDestroyInOnDestroy() at /Shapes/Scripts/Runtime/Utils/ShapesExtensions.cs:84
82: }; // execute late in this editor frame, if still not playing
83: else
--> 84: Object.Destroy( obj );
85: #else
86: Object.Destroy( obj );
ShapeRenderer.TryDestroyInstancedMaterials() at /Shapes/Scripts/Runtime/Components/ShapeRenderer.cs:382
380: if( instancedMaterials[i] != null ) {
381: if( inOnDestroy )
--> 382: this.TryDestroyInOnDestroy( instancedMaterials[i] );
383: else
384: instancedMaterials[i].DestroyBranched();
ShapeRenderer.OnDestroy() at /Shapes/Scripts/Runtime/Components/ShapeRenderer.cs:349
347: this.TryDestroyInOnDestroy( rnd );
348: this.TryDestroyInOnDestroy( mf );
--> 349: TryDestroyInstancedMaterials( inOnDestroy: true );
350: }
Can confirm that this issue exists since Shapes 4.4.0. In my case, ShapeRenderer component seems to try to destroy material assets when the component is destroyed. Replacing this line in ShapeRenderer.cs:430 prevents Shapes from trying to destroy material assets & fixes the issue.