Version 2.1.0.0

Odin has a dedicated attribute overview with examples

ButtonAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class ButtonAttribute : ShowInInspectorAttribute, _Attribute

Buttons are used on functions, and allows for clickable buttons in the inspector.

Inheritance
Example

The following example shows a component that has an initialize method, that can be called from the inspector.

public class MyComponent : MonoBehaviour
{
	[Button]
	private void Init()
	{
		// ...
	}
}
Example

The following example show how a Button could be used to test a function.

public class MyBot : MonoBehaviour
{
	[Button]
	private void Jump()
	{
		// ...
	}
}
Example

The following example show how a Button can named differently than the function it's been attached to.

public class MyComponent : MonoBehaviour
{
	[Button("Function")]
	private void MyFunction()
	{
		// ...
	}
}

Constructors

ButtonAttribute()
Creates a button in the inspector named after the method.
public ButtonAttribute()
ButtonAttribute(ButtonSizes)
Creates a button in the inspector named after the method.
public ButtonAttribute(ButtonSizes size)
Parameters
ButtonSizes size

The size of the button.

ButtonAttribute(ButtonSizes, ButtonStyle)
Creates a button in the inspector named after the method.
public ButtonAttribute(ButtonSizes size, ButtonStyle parameterBtnStyle)
Parameters
ButtonSizes size

The size of the button.

ButtonStyle parameterBtnStyle

Button style for methods with parameters.

ButtonAttribute(ButtonStyle)
Creates a button in the inspector named after the method.
public ButtonAttribute(ButtonStyle parameterBtnStyle)
Parameters
ButtonStyle parameterBtnStyle

Button style for methods with parameters.

ButtonAttribute(Int32)
Creates a button in the inspector named after the method.
public ButtonAttribute(int buttonSize)
Parameters
System.Int32 buttonSize

The size of the button.

ButtonAttribute(Int32, ButtonStyle)
Creates a button in the inspector named after the method.
public ButtonAttribute(int buttonSize, ButtonStyle parameterBtnStyle)
Parameters
System.Int32 buttonSize

The size of the button.

ButtonStyle parameterBtnStyle

Button style for methods with parameters.

ButtonAttribute(String)
Creates a button in the inspector with a custom name.
public ButtonAttribute(string name)
Parameters
System.String name

Custom name for the button.

ButtonAttribute(String, ButtonSizes)
Creates a button in the inspector with a custom name.
public ButtonAttribute(string name, ButtonSizes buttonSize)
Parameters
System.String name

Custom name for the button.

ButtonSizes buttonSize

Size of the button.

ButtonAttribute(String, ButtonSizes, ButtonStyle)
Creates a button in the inspector with a custom name.
public ButtonAttribute(string name, ButtonSizes buttonSize, ButtonStyle parameterBtnStyle)
Parameters
System.String name

Custom name for the button.

ButtonSizes buttonSize

Size of the button.

ButtonStyle parameterBtnStyle

Button style for methods with parameters.

ButtonAttribute(String, ButtonStyle)
Creates a button in the inspector with a custom name.
public ButtonAttribute(string name, ButtonStyle parameterBtnStyle)
Parameters
System.String name

Custom name for the button.

ButtonStyle parameterBtnStyle

Button style for methods with parameters.

ButtonAttribute(String, Int32)
Creates a button in the inspector with a custom name.
public ButtonAttribute(string name, int buttonSize)
Parameters
System.String name

Custom name for the button.

System.Int32 buttonSize

Size of the button in pixels.

ButtonAttribute(String, Int32, ButtonStyle)
Creates a button in the inspector with a custom name.
public ButtonAttribute(string name, int buttonSize, ButtonStyle parameterBtnStyle)
Parameters
System.String name

Custom name for the button.

System.Int32 buttonSize

Size of the button in pixels.

ButtonStyle parameterBtnStyle

Button style for methods with parameters.

Fields

ButtonHeight
Gets the height of the button. If it's zero or below then use default.
public int ButtonHeight
Expanded
If the button contains parameters, you can disable the foldout it creates by setting this to true.
public bool Expanded
Name
Use this to override the label on the button.
public string Name
Style
The style
public ButtonStyle Style