Hi Everyone.
I’ve been struggling with a serious issue for over 8 hours, and it’s driving me crazy…
Whenever I try to render a texture in the Editor preview (using GUI.DrawTexture()
), there’s a loading time of 15-20 seconds for UnityEditor.CoreModule.dll
.
If I try to render a texture on every UI Editor refresh (as I usually do), I might as well say goodbye to my PC…
I’ve looked everywhere on Google but haven’t found anything useful. (I don’t use Plastic SCM or Unity Version Control. I’ve tried clearing the cache, removing the library folder, restarting my PC, changing Visual Studio versions, etc.) However, after creating a super minimal project, I was able to finally pinpoint what was causing the issue.
I know this is working fine on 2022.3.26f1 (tested on a Win10 and a Linux) but NOT working on 2022.3.45f1 (Win10) and 2022.3.47f1 (Linux)…
The simple way to reproduce my issue is:
- Create a new project on 2022.3.45+ (or 6-preview)
- Create a MonoBehaviour “TestMono”
- Add this script to any GameObject and select it (to display it on Inspector)
- Create an Editor Script:
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TestMono))]
public class TestMonoEditor : Editor
{
public override bool HasPreviewGUI()
{
return true;
}
public override GUIContent GetPreviewTitle()
{
return new GUIContent("Test DrawPreview");
}
public override void DrawPreview(Rect previewArea)
{
Texture2D tex = new Texture2D((int)previewArea.width, (int)previewArea.height);
Color32[] pixels = new Color32[tex.width * tex.height];
int index = 0;
for (int y = 0; y < tex.height; y++)
{
for (int x = 0; x < tex.width; x++)
{
pixels[index++] = new Color32(0, 0, 0, 255);
}
}
tex.SetPixels32(pixels);
tex.Apply();
GUI.DrawTexture(previewArea, tex, ScaleMode.StretchToFill, false);
}
}
BOOM! Computer crash.
I also tried to generate this same Texture on the MonoBehaviour method (I update the function to give an arbitrary Rect Rect previewArea = new Rect(0, 0, 512, 512);
and commented the last line GUI.DrawTexture
and it’s working fine.
So the issue is when Unity run GUI.DrawTexture()
.
Does anyone have any information that could help me? I’m going crazy and really don’t know what else to do.