• 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 /
This question was closed Apr 01, 2018 at 02:15 PM by meat5000 for the following reason:

Questions exists : https://answers.unity.com/questions/1005277/can-i-change-variable-name-on-inspector.html

avatar image
2
Question by llfranco712 · Apr 01, 2018 at 12:42 AM · scripting problemscript.

Change a variable name only on the Inspector

Can I change a variable name so that it shows its original name inside my script but on the Inpector some other name from my preference?


For example, I wanna change this variable name so that is shows some other name on the Inspector alt text alt text

capturar.png (1.4 kB)
capturar2.png (13.8 kB)
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 meat5000 ♦ · Apr 01, 2018 at 02:14 PM 0
Share

'Duplicate' question

https://answers.unity.com/questions/1005277/can-i-change-variable-name-on-inspector.html

2 Replies

  • Sort: 
avatar image
11
Best Answer

Answer by Hellium · Apr 01, 2018 at 10:21 AM

For sure you can! And it's not that hard!

Create a first script called RenameAttribute.cs and copy paste the following code:

 using UnityEngine;
 
 public class RenameAttribute : PropertyAttribute
 {
     public string NewName { get ; private set; }    
     public RenameAttribute( string name )
     {
         NewName = name ;
     }
 }

Then, create an other script called RenameDrawer. Place this script in a folder called Editor

 using UnityEngine;
 using UnityEditor;
 
 [CustomPropertyDrawer(typeof(RenameAttribute))]
 public class RenameEditor : PropertyDrawer
 {
     public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
     {
         EditorGUI.PropertyField(position, property, new GUIContent( (attribute as RenameAttribute).NewName ));
     }
 }

Finally, in your original script, add the attribute we've just created:

 [Rename("My super properties!"]
 public TPC_Properties properties;
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 llfranco712 · Apr 01, 2018 at 11:39 PM 0
Share

It doesn't recognize the function Rename :/

All my scripts are inside the namespace SA, and I already tried taking all of them out of this namespace and putting the scripts you shared with me inside of this namespace as well and none worked.

I did put the scripts inside of a folder called Editor, so I don't really know what else I could do. I'm using 2 scripts to draw the components of a scriptable object on the Inspector and they work just fine.

Any thoughts?

Image to the script

avatar image Hellium llfranco712 · Apr 02, 2018 at 08:54 AM 0
Share
  • The name of the 2nd script should be RenameEditor ins$$anonymous$$d of`RenameDrawer` (or change the name of the class), my bad, sorry

  • The RenameAttribute.cs file, should be outside of the Editor folder

The namespaces should not be a problem. But the two classes in your namespace if it's more convenient for you.

avatar image Kali2048 Hellium · Jan 26, 2019 at 10:44 AM 0
Share

Is there any way to make this work with Array ? Right now it seems to be renaming each element of the array but not the array itself. Thanks

Show more comments
avatar image llfranco712 · Apr 02, 2018 at 05:37 PM 0
Share

It worked now! Thanks bro, cheers from Brazil :))

avatar image
-3

Answer by RVDL_IT · Apr 01, 2018 at 12:45 AM

No, you can't. If you really want to you can make the variable private and make a new variable that is the same.

 public bool PublicBool;
 private bool OriginalBool;
 
 PublicBool = OriginalBool;
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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

143 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 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 can I rotate all the objects ? One of them is never rotating 0 Answers

problems with List 0 Answers

Public list are not reflecting in inspector. 1 Answer

How can calculate the drawn circle range ? 1 Answer

How can i create array of texture2d with variables names ? 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