Search Issue Tracker

Fixed in 2021.2.X

Planned for 2021.1.X



Found in


Issue ID




Texture Importer Inspector throws errors when a built-in texture inspector is overwritten in C#



When a custom inspector targetting Texture2D, Cubemap or Texture3D is present in the project, the texture importer inspector of these assets throws errors when they are displayed in the inspector window.

Stacktrace of the error:
InvalidCastException: Specified cast is not valid.
UnityEditor.TextureImporterInspector.get_textureInspector () (at <280242b5f32c446482b2e1fcdf7e6d80>:0)
UnityEditor.TextureImporterInspector.DrawPreview (UnityEngine.Rect previewArea) (at <280242b5f32c446482b2e1fcdf7e6d80>:0)
UnityEditor.PropertyEditor.DrawPreviewAndLabels () (at <280242b5f32c446482b2e1fcdf7e6d80>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <b50b24924f4d442fb2face92883f4dc2>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Here's an example of custom editor that causes the error:
[CustomEditor(typeof(Texture2D), false)]
class MixtureInspectorTexture2D : MixtureEditor
public override bool HasPreviewGUI() => true;

Repro steps:
- Download the repro project
- Select the texture A in the Assets folder
- Observe errors in the console, like in the attached gif.

Note that the issue doesn't repro on 2020.2. Tested on Unity 2021.1 and 2021.2.

Comments (1)

  1. 9a6b0886392d64ff6efe7724c30bb8eb?d=mm


    Feb 25, 2021 20:32

    Excellent post.
    Looking for any electronic appliances ot gadgets.
    https://uncleguides.comIt provides you the information for all the products.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.