Version 3.1.11.0

Odin has a dedicated attribute overview with examples

ButtonAttribute 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 = false)]
[Conditional("UNITY_EDITOR")]
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
DirtyOnClick
Whether the containing object or scene (if there is one) should be marked dirty when the button is clicked. True by default.
public bool DirtyOnClick
DisplayParameters

Whether to display the button method's parameters (if any) as values in the inspector. True by default.

If this is set to false, the button method will instead be invoked through an ActionResolver or ValueResolver (based on whether it returns a value), giving access to contextual named parameter values like "InspectorProperty property" that can be passed to the button method.

public bool DisplayParameters
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 in which to draw the button.
public ButtonStyle Style

Properties

DrawResult
If the button has a return type, set this to false to not draw the result. Default value is true.
public bool DrawResult { get; set; }
DrawResultIsSet
public bool DrawResultIsSet { get; }