Version 2.1.0.0

Odin has a dedicated attribute overview with examples

DisplayAsStringAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
public sealed class DisplayAsStringAttribute : Attribute, _Attribute

DisplayAsString is used on any property, and displays a string in the inspector as text.

Use this for when you want to show a string in the inspector, but not allow for any editing.

Inheritance
  • System.Object
  • System.Attribute
  • DisplayAsStringAttribute
Remarks

DisplayAsString uses the property's ToString method to display the property as a string.

Example

The following example shows how DisplayAsString is used to display a string property as text in the inspector.

public class MyComponent : MonoBehaviour
{
	[DisplayAsString]
	public string MyInt = 5;

	// You can combine with HideLabelAttribute to display a message in the inspector.
	[DisplayAsString, HideLabel]
	public string MyMessage = "This string will be displayed as text in the inspector";

	[DisplayAsString(false)]
	public string InlineMessage = "This string is very long, but has been configured to not overflow.";
}

Constructors

DisplayAsStringAttribute()
Displays the property as a string in the inspector.
public DisplayAsStringAttribute()
DisplayAsStringAttribute(Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow)
Parameters
System.Boolean overflow

Value indicating if the string should overflow to multiple lines or not.

Fields

Overflow
If true the string will overflow to multiple lines, if there's not enough space when drawn.
public bool Overflow