ButtonAttribute

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

namespace Sirenix.OdinInspector
{
[AttributeUsageAttribute((AttributeTargets)64, AllowMultiple = False, Inherited = False)]
public class ButtonAttribute : ShowInInspectorAttribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 2.0.0.0

See Also

Fields

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

Constructors

Definition Description
ButtonAttribute() Creates a button in the inspector named after the method.
ButtonAttribute(ButtonSizes) Creates a button in the inspector named after the method.
ButtonAttribute(ButtonSizes, ButtonStyle) Creates a button in the inspector named after the method.
ButtonAttribute(ButtonStyle) Creates a button in the inspector named after the method.
ButtonAttribute(int) Creates a button in the inspector named after the method.
ButtonAttribute(int, ButtonStyle) Creates a button in the inspector named after the method.
ButtonAttribute(string) Creates a button in the inspector with a custom name.
ButtonAttribute(string, ButtonSizes) Creates a button in the inspector with a custom name.
ButtonAttribute(string, ButtonSizes, ButtonStyle) Creates a button in the inspector with a custom name.
ButtonAttribute(string, ButtonStyle) Creates a button in the inspector with a custom name.
ButtonAttribute(string, int) Creates a button in the inspector with a custom name.
ButtonAttribute(string, int, ButtonStyle) Creates a button in the inspector with a custom name.

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()
	{
		// ...
	}
}