- Home /
Custom Inspector: Object field instead of Texture2D field
I'm using EditorGUILayout.ObjectField with the filter set to Texture2D. is there a way to force it to show a standard object reference field instead of the texture preview field?
You could look into modifying EditorStyles.objectField$$anonymous$$iniThumb or creating your own custom GUIStyle and passing it as a parameters
Answer by PowerhoofDave · Sep 01, 2016 at 08:35 AM
If anyone has the same problem but with EditorGUI.ObjectField, I found that if you set the height of its rect to 16 or less it will render as the standard object reference field.
Answer by ZenMicro · Jan 14, 2016 at 07:37 PM
I found with a sprite at least if you use the overload function that does not have a label it will present as an inline object field, if i use the overload with a title (even if i set it to "") i get the image display.
sprite = (Sprite)EditorGUILayout.ObjectField("Sprite", sprite, typeof(Sprite), allowSceneObjects: true);
Will present itself as an image view with the select button within the bottom right corner
sprite = (Sprite)EditorGUILayout.ObjectField(sprite, typeof(Sprite), allowSceneObjects: true);
This will present itself as a standard inline object field. Might not be what some are looking for as a label is usually desired but you could add a label in a EditorGUILayout.BeginHorizontal(); call or something , just something I stumbled onto, It would be more helpful if there was a parameter in the EditorGUILayout.ObjectField to display as Text or Object, but anyway there it is.
any idea if we are able to allighn it to the left hand side of the Editor, its aligned to the right
Answer by bluksPL · Oct 17, 2016 at 01:16 PM
It's old post but...
Instead of writing:
sprite = (Sprite)EditorGUILayout.ObjectField("Sprite", sprite, typeof(Sprite), allowSceneObjects: true);
We just need to make it like it:
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Source Image");
sprite = (Sprite)EditorGUILayout.ObjectField(sprite, typeof(Sprite), allowSceneObjects: true);
EditorGUILayout.EndHorizontal();
And we have Field for Sprites like in Image Component.
I think code is simple enough to understand.
I hope it helped. ;)
Answer by RealSoftGames · Aug 11, 2019 at 07:05 AM
sorry for oppening an old thread. for anyone else looking at getting a sprite to render with a label on a single line without it being so bulky you can use a Horizontal group
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Override Icon");
overrideIcon.objectReferenceValue =
(Sprite)EditorGUILayout.ObjectField(overrideIcon.objectReferenceValue,
typeof(Sprite), allowSceneObjects: false);
EditorGUILayout.EndHorizontal();
Answer by Paul_Bronowski · Sep 27, 2018 at 06:46 PM
Old post, but I ran into this recently. The type parameter is a signal to ObjectField() for which type of GUI layout control to present, as well as a hint for what to use as a filter for the ObjectPicker. The fields meaning seems a bit overloaded. If you use typeof(Sprite) or typeof(Texture2D), for example, it will present the corresponding 'advanced' control types. If you want the usual one-line compact ObjectField control, pass typeof(Object). This does have the side-effect of generating an ObjectPicker filter for Objects, and not one more specific for Sprite/Textures. And, unfortunately, passing a filter string to ObjectField doesn't seem possible, so if you need that functionality, yes you build out a custom line per previous comments and other web posts.
cheers
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Terrain bumped specular material not working 1 Answer
Allow editing of textures once built? 1 Answer
How do I clamp a texture on only 1 axis? 0 Answers