Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to avoid saving mesh to scene file
#1
Hello,

How can I get Obi Rope to not persist the mesh within the scene? Every time I open/save my scene containing Obi Rope, the scene contains changed lines from the mesh apparently being regenerated/updated, which becomes cumbersome to discard in order to keep source control commits clean.

Thanks!
Reply
#2
(22-09-2023, 10:16 PM)imtzo Wrote: Hello,

How can I get Obi Rope to not persist the mesh within the scene? Every time I open/save my scene containing Obi Rope, the scene contains changed lines from the mesh apparently being regenerated/updated, which becomes cumbersome to discard in order to keep source control commits clean.

Thanks!

Hi,

The rope mesh is not persisted within the scene. You can check this in ObiRopeExtrudedRenderer.cs, the mesh is declared as:

Code:
[HideInInspector] [NonSerialized] public Mesh extrudedMesh;

Being NonSerialized, it won't be saved to the scene.

I can't identify any changes being made to the scene when opening/saving scenes that use ropes. Could you be more specific as to what lines are being picked up by your source control system?

kind regards,
Reply
#3
(26-09-2023, 07:22 AM)josemendez Wrote: I can't identify any changes being made to the scene when opening/saving scenes that use ropes. Could you be more specific as to what lines are being picked up by your source control system?

Sure, I see sets of changed lines in the diff, with the name "extrudedMesh", which looks to be the name ObiRopeLineRenderer uses.

Interestingly, the Object ID shown for each Mesh is not shown elsewhere in the file, so it seems that while they are not being referenced, they are being saved in the file (leaked?). (I am not a .scene file expert, but this is my understanding of how they work.)

In case it's important, my ObiRope objects are defined in prefabs, and I'm using instances of this prefab within my scene. There is one mesh removed/deleted for each instance (two instances at present). Could this be related?

Further details below. Thanks!


Lines removed:

Code:
--- !u!43 &454250562
Mesh:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_Name: extrudedMesh
  serializedVersion: 10
  m_SubMeshes:
  - serializedVersion: 2
...<snipped, but includes very lengthy fields for _typelessdata and m_IndexBuffer>

Lines added:

Code:
--- !u!43 &1380844300
Mesh:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_Name: extrudedMesh
  serializedVersion: 10
  m_SubMeshes:
...<snipped, but includes very lengthy fields for _typelessdata and m_IndexBuffer>


Object setup:

   
Reply
#4
Hi,

Could reproduce this.

"extrudedMesh" is explicitly marked as non-serialized, since it's created entirely from scratch when you create the renderer and destroyed afterwards and there's no need to store it anywhere. However, the script serializing it is not ObiRopeExtrudedRenderer but Unity's MeshFilter, which the mesh is assigned to in order to be rendered. You can check this by looking at the MeshFilter's referenced file id, should be 1380844300 as per the scene snippet you shared, something like:

Quote:MeshFilter:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: anyNumber}
  m_Mesh: {fileID: 1380844300}

Seems like the MeshFilter component will serialize the mesh assigned to it in case it's not an asset stored in disk, even if the script creating it holds a non-serialized reference to it. As far as I know we have no way to modify this behavior, as MeshFilter is a built-in Unity component.

kind regards,
Reply
#5
I was able to fix this by setting the hide flags on the mesh upon creation in ObiRopeExtrudedRenderer:

Code:
extrudedMesh.hideFlags = HideFlags.DontSave;

This prevents the mesh from being serialized with the scene file for me in 2021.3.30f1.
Reply
#6
(02-10-2023, 04:13 PM)imtzo Wrote: I was able to fix this by setting the hide flags on the mesh upon creation in ObiRopeExtrudedRenderer:

Code:
extrudedMesh.hideFlags = HideFlags.DontSave;

This prevents the mesh from being serialized with the scene file for me in 2021.3.30f1.

Thanks! I'm glad you were able to figure it out. We'll evaluate and potentially introduce this change in the next update.

kind regards,
Reply
#7
+1. Always good to get rid of unneeded scene changes
Reply