Suggestion attributes

Custom suggestion attributes

Most parameter types such as enum, bool, Color and derivatives from UnityEngine.Object already comes with suggestions. However, it's also possible to define your own custom suggestions that you can specify on individual parameters.

To define your own suggestions, make a new class that inherits from SuggestionAttribute:

public class PositionAttribute : SuggestionAttribute
{
    public override IEnumerable<string> Get()
    {
        string[] positions = { "(0,0,0)", "(20,10,20)", "(5,100,5)" };
        return positions;
    }
}

Then to see the suggestions on a parameter, put the attribute on the parameter in the method.

public class Player : MonoBehaviour
{
    [Command]
    public void Teleport([Position] Vector3 position)
    {
        transform.position = position;
    }
}

Built-in suggestion attributes

  • [SceneName] - List of all scenes.

  • [CommandName] - List of all loaded commands.

Last updated