Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
21
Question by xEnOnn · Mar 26, 2013 at 03:58 AM · variableinspector

Showing a textarea field for a string variable in inspector?

When I declare a public string variable in my script, the Unity inspector shows a single-line textfield where I can edit text for the variable. Since the string is intended to store a long message, is it possible for me to get the Unity inspector to show up as a multi-line textarea field for the variable instead?

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

4 Replies

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

Answer by Chronos-L · Mar 26, 2013 at 05:01 AM

Use custom editor: ## Example Script ##

 public class TextAreaScript : MonoBehaviour {
 
     public string longString;
 }

Custom Editor Script (Placed in Assets/Editor)

 using UnityEditor;
 using UnityEngine;
 
 [CustomEditor(typeof(TextAreaScript)), CanEditMultipleObjects]
 public class TextAreaEditor : Editor {
     
     public SerializedProperty longStringProp;

     void OnEnable () {
         longStringProp = serializedObject.FindProperty ("longString");
     }
     
     public override void OnInspectorGUI() {
         serializedObject.Update ();
         longStringProp.stringValue = EditorGUILayout.TextArea( longStringProp.stringValue, GUILayout.MaxHeight(75) );
         serializedObject.ApplyModifiedProperties ();
     }
 }
 
Comment
Add comment · Show 5 · 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 Ash-Blue · Jul 25, 2014 at 08:28 AM 0
Share

I just gave this a test run in Unity 4.5. $$anonymous$$aybe I'm missing a step, but it doesn't seem to be working.

avatar image CoatsinkPC · Aug 02, 2014 at 09:11 PM 0
Share

Works for me. Did you copy the code exactly? and did you place the second script in a folder named "Editor"?

avatar image CandyCreep · Aug 29, 2016 at 04:32 PM 1
Share

This method doesn't seem to have word-wrapping, like the method "andsee" came with - which is also much cleaner and simpler to use (one line over the desired string): [TextArea(3, 10)]

avatar image sh_code · Sep 12, 2019 at 03:11 PM 0
Share

This SHOULD NOT be tagged as the best answer. The one right below this one should. [TextArea(3,10)] annotation in front of the string, done.

avatar image Bunny83 sh_code · Sep 12, 2019 at 03:43 PM 0
Share

Actually when the question was asked the $$anonymous$$ultiline / TextArea attribute and the corresponding built in property drawer did not exist yet. So this answer was the answer back then and still answers the question that the OP had asked back then. $$anonymous$$eep in $$anonymous$$d that it's the duty of the OP to pick an answer and he did back then. This answer is still valid, even there might be a simpler / built-in solution now.


You should not bump such ancient and you should save your downvotes for actual wrong information. Creating a custom inspector (or nowadays a custom property drawer) actually gives you much more possibilities than the built-in textarea property drawer.

avatar image
157

Answer by andsee · Aug 18, 2014 at 10:53 AM

You can use the TextArea attribute before the property you want to display:

 [TextArea(3,10)]
 public string myText = "This text will appear in a text area that automatically expands";

http://docs.unity3d.com/ScriptReference/TextAreaAttribute.html

Comment
Add comment · Show 5 · 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 JoeStrout · Jul 02, 2015 at 05:12 AM 5
Share

This really ought to be the accepted answer... it's simple, it works, and nobody has to get nailed to anything.

avatar image zangad · Jul 26, 2015 at 02:17 AM 2
Share

This worked perfectly for me. I agree, it should be the accepted answer.

avatar image Beguiled · Apr 08, 2016 at 06:57 PM 2
Share

Agreed. This is by far the preferable solution in my opinion.

avatar image cwbeta · Sep 05, 2017 at 08:30 AM 0
Share

IT'S AWESO$$anonymous$$E!!!!!!!

avatar image paul-masri-stone · Dec 09, 2021 at 02:12 PM 0
Share

Unlike [Multiline] this automatically wraps long lines. It also displays the textarea beneath the label, full width, rather than to the right of the label.

avatar image
36

Answer by menelaus · Apr 22, 2014 at 01:42 PM

For C#;

 [Multiline]
     public string Note = "this is multiline string \n as you can see..";
 
Comment
Add comment · Show 2 · 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 plasticYoda · Jul 14, 2014 at 07:50 PM 0
Share

Only works with linebreaks in the string - will not soft-wrap a string that is too long.

avatar image Ash-Blue · Jul 25, 2014 at 08:24 AM 1
Share

@plasticYoda Note that to my knowledge there are no solutions to making it auto-wrap without writing some robust code that re-calculates wrapping for you automatically.

avatar image
1

Answer by Eric5h5 · Mar 26, 2013 at 04:06 AM

You can make a custom inspector.

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

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

20 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

Related Questions

A node in a childnode? 1 Answer

How to expose variables in c# according to selected booleans 1 Answer

How can I get all the option this guide has in his inspector 1 Answer

Exposed Areas 1 Answer

How can i assign prefab to variable without drag & drop from project to inspector. 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