Displaying a Texture2D in window in real time

Hello

I am having a difficult time displaying a Texture2D as RGBA Float32 format in my inspector i do not know how to fix it.

Currently i have:

        public override void OnInspectorGUI ()
        {
            Spectra myTarget = (Spectra)target;
            DrawDefaultInspector();

            var texture = AssetPreview.GetAssetPreview(myTarget.H0T);
            GUILayout.Label(texture);
        }

But it won’t update the preview of the image in real time when the image is changing, how can i fix it ? It seems to just show a snapshot, which is annoying.

The editor GUI only redraws when you interact with it. You will need to trigger a redraw of the editor GUI whenever you want to update the image. A naive way to do this is to add a call to Editor.Repaint at the end of OnInspectorGUI, but this will cause the editor to always redraw every frame, which is not ideal for editor performance. It would be better if you determine the conditions under which the texture changes and only repaint then.

Another potential issue is the call to GetAssetPreview. This is a method controlled by Unity, and as such it is a black box with regards to how it creates its textures and how it caches them (if at all). It may not be updating because unity is caching the original texture, or it’s not taking the changes you’re making into account when generating it. If you want total control over your texture including how it updates over time it is best to generate it yourself.

Can the target script “Spectra” which updates the image data, call it’s editor script by calling a public function to repaint some how ? Only issue currently is editor stuff is in the editor assembly. So they don’t directly connect.