- Home /
UV shifting script "leaks meshes" in editor
So, I'm using an edited version of a UV shifting script in order to shift UVs from within the editor. The idea is to use this script in order to recolour level features by shifting their UVs to other spots on an atlas containing many colour variations. The problem is the editor is telling me that I'm "leaking meshes" when using the script. Any ideas of how I could implement this differently in order to avoid the errors?
Here is the script:
#pragma strict
@script ExecuteInEditMode()
public var uOffset : float = 0.25f;
public var vOffset : float = 0.25f;
public var AddU : boolean = false;
public var SubU : boolean = false;
public var AddV : boolean = false;
public var SubV : boolean = false;
function Start()
{
this.enabled = false;
}
function Update()
{
if (AddU)
{
SetUVs(uOffset,0.0f);
AddU = false;
}
if (SubU)
{
SetUVs(-uOffset,0.0f);
SubU = false;
}
if (AddV)
{
SetUVs(0.0f,vOffset);
AddV = false;
}
if (SubV)
{
SetUVs(0.0f,-vOffset);
SubV = false;
}
}
function SetUVs(u : float , v : float)
{
// Build the uvs
var uvs : Vector2[] = new Vector2[(GetComponent(MeshFilter) as MeshFilter).mesh.vertices.Length];
uvs = (GetComponent(MeshFilter) as MeshFilter).mesh.uv; // Take the existing UVs
for (var i = 0 ; i < uvs.Length; i++) uvs[i] = Vector2 (uvs[i].x + u, uvs[i].y + v); // Offset all the UV's
// Apply the modded UV's
(GetComponent(MeshFilter) as MeshFilter).mesh.uv = uvs;
}
Answer by tanoshimi · Feb 17, 2015 at 05:38 PM
It would be helpful if you gave the exact error message but, according to http://www.west-racing.com/mf/?wp_super_faq=i-get-an-error-message-about-sharedmesh-leaking-when-i-add-a-modifier
"This is a false error that Unity gives to any system that alters a mesh in Edit Mode, so all systems that build or alter meshes while not in run mode will produce the error eg RageSpline, ezGUI etc. Rest assured there are no leaked meshes and nothing is actually wrong. The error does not happen during runtime."
"Instantiating mesh due to calling $$anonymous$$eshFilter.mesh during edit mode. This will leak meshes. Please use $$anonymous$$eshFilter.shared$$anonymous$$esh ins$$anonymous$$d. UnityEngine.$$anonymous$$eshFilter:get_mesh() ShiftUVs:SetUVs(Single, Single) (at Assets/Louis Assets/Scripts/ShiftUVs.js:46) ShiftUVs:Update() (at Assets/Louis Assets/Scripts/ShiftUVs.js:22)"
is the error I get in the editor. Also, the name of the mesg on which I use the UV shift changes to "NA$$anonymous$$E Instance". And if I remove the "this.enable = false" from the Start() function, then entering play mode and back and subsequently using the UV shift edit mode causes the word "Instance" to keep getting added on over and over, like : "NA$$anonymous$$E Instance Instance Instance" etc.
I get that it's "Not a real error" but it really does seem to be re-instantiating the mesh every time. At least every time I use it again after exiting play mode.
Oh, also, looks like I get this error when saving the scene "Cleaning up leaked objects in scene since no game object, component or manager is referencing them $$anonymous$$esh Block_4x2x4 Instance Instance has been leaked 1 times."
Your answer

Follow this Question
Related Questions
UV Image Map Animation 1 Answer
Memory Leak Adventures in Editor (3.4, lot of instantiated objects) 1 Answer
Voxel retexture problem 0 Answers