I have got a static class which has a function hooked up to EditorApplication.update;
During each update, I am using Graphics.DrawMesh(), which makes a cube spawn in the world.
Now, the interesting part is, because every update I call DrawMesh(), for some reason, the old meshes don’t clear themselves, unless I move or rotate or scale any object within the scene. If I disable components / gameObjects it also will clean the old meshes from the screen.
So if it’s left running, it will keep spawning cube meshes in a specified range. It will clear them up as soon as I move, rotate or scale something within the scene.
SceneVeiw.RepaintAll() at the start of my update doesn’t help to remove the old meshes
If you don’t know the answer, at least tell me, what sort of function gets called when I move the object? Clearly it’s different to just flying around the scene.
Thank you very much!
Have a look:
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
static public class meshDrawer {
static Mesh aMesh;
static Material aMaterial;
static meshDrawer(){
EditorApplication.update -= Update;
EditorApplication.update += Update;
aMesh = GameObject.Find("Cube").GetComponent<MeshFilter>().sharedMesh;
aMaterial = GameObject.Find("Cube").renderer.sharedMaterial; //You will need a cube object in your hierarchy for this to work
}
static void Update() {
Graphics.DrawMesh(aMesh, new Vector3(Random.Range (0f,2f), Random.Range(0f,4f), Random.Range(0f,2f)), Quaternion.identity, aMaterial, 0);
}
}
What da heck?
How can we make it draw one mesh per the update callback, and clean the old ones every callback?