Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by darman96 · Dec 08, 2016 at 06:52 AM · guitextfieldiconcustom inspector

Custom Inspector, Textfield with Icon

Hi,

I'm currently fooling around with some custom inspector stuff and since in the unity default inspector you can often see textfields with an icon inside the textfield I wondered how they did this? Look for example at the first item in every monobehaviour inspector where they show the script name, there's a little c# script icon right in front of the text. Does somebody know how to achieve this?

Greetings

Comment
Add comment
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 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Adam-Mechtley · Dec 08, 2016 at 09:16 AM

Hi! That particular field is an ObjectField, not a text field. Object fields (i.e. a serialized field that contains a reference to a UnityEngine.Object of some kind) will display the icon associated with the type in question. For custom scripts (e.g., MonoBehaviours or ScriptableObjects) this icon is the one specified on the script asset in your project view (up at the very top left of the Inspector when you have the script selected).

That said, if you are wanting to actually implement a text field with an icon or something on it, I strongly recommend you check out the PropertyDrawer class.

Comment
Add comment · Show 7 · 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 darman96 · Dec 08, 2016 at 09:29 AM 0
Share

Thanks for the reply. Yeah the ObjectField works but it says that it's deprecated.

avatar image darman96 darman96 · Dec 08, 2016 at 09:31 AM 0
Share

Oh never$$anonymous$$d it was just this version of the ObjectField method which is deprecated :D

avatar image darman96 · Dec 08, 2016 at 09:41 AM 0
Share

Okay when I pass in the target field of my custom inspector as object it always say "GameObjectName (ScriptName)" in the unity editor, do you know how i can get it to just show the script name?

avatar image Adam-Mechtley darman96 · Dec 08, 2016 at 09:56 AM 1
Share

The reason the script field does not show the type in parentheses is that its type filter is set to typeof (UnityEditor.$$anonymous$$onoScript). If your type filter is e.g., a component type, then the text in the field will show you the GameObject name as well as the component type in parentheses so you have enough context to know what the object reference is. If you are just trying to show the script field in a custom Editor though, you can use:

 EditorGUILayout.PropertyField (serializedObject.FindProperty ("m_Script"));
avatar image darman96 Adam-Mechtley · Dec 08, 2016 at 10:07 AM 0
Share

Thanks again it works now

Show more comments

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

95 People are following this question.

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

Related Questions

How should I generate an image of a model? 1 Answer

How to speed up TextField input? 0 Answers

Input not registering while TextField is selected 3 Answers

Lock a textarea/textfield for editing 1 Answer

GUI textfield duplicate text 0 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