Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by kitsee · Jul 21, 2015 at 03:56 PM · texturecustom-inspector

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PouletFrit · Jul 21, 2015 at 05:01 PM 0
Share

You could look into modifying EditorStyles.objectField$$anonymous$$iniThumb or creating your own custom GUIStyle and passing it as a parameters

6 Replies

· Add your reply
  • Sort: 
avatar image
7

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
5

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RealSoftGames · Aug 09, 2016 at 02:17 PM 0
Share

any idea if we are able to allighn it to the left hand side of the Editor, its aligned to the right

avatar image
5

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. ;)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

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();

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 11, 2019 at 09:25 AM 0
Share

That's exactly what bluksPL posted about 3 years ago.

avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Two-sided Objects from Blender to Unity3d 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges