Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Any chance of some more Property Attributes?

Discussion in '2017.2 Beta' started by CDF, Jul 29, 2017.

  1. CDF


    Sep 14, 2013
    Would love if some more attributes could be added into the new beta.
    I find myself using these a lot:

    value must be greater than 0

    value must be less than 100

    int value is mask enum (System.Flags)

    [Help("Don't toggle this", MessageType.Warning)]
    draws a help box with message above the field

    int value is a game object layer

    at the very least, imo, a "Min" attribute should be standard, ensuring a value is greater than 0 is my daily life.
    Last edited: Jul 29, 2017
  2. hippocoder


    Digital Ape Moderator

    Apr 11, 2010
    A label attribute would be greatly welcome but for the rest simply use OnValidate()

    Code (CSharp):
    1.     void OnValidate()
    2.     {
    3.         if (value < 0) value = 0;
    4.     }
    For example. It is called whenever someone diddles with stuff in the inspector, and is precisely for your problem.
  3. AlkisFortuneFish


    Apr 26, 2013
    We've had these in the project for so long that I forgot they were not in fact standard! :p