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 sealed class ButtonAttribute : ShowInInspectorAttribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 1.0.5.0

See Also

Constructors

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

Properties

Return Type Definition Description
int ButtonHeight Gets the height of the button. If it's zero or below then use default.
string Name Use this to override the label on the button.

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