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
114078-capturar.png
114079-capturar2.png

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

–

2 Answers

2

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;

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;