I made two useful Custom Attributes : Min and Max. They require one parameter, an int or a float, and respectively prevent a class member value to be less or more than the given parameter.
Only the first CustomAttribute (Min, in this example) will be used. But with the Unity attributes I can use at the same time SerializeField and HideInInspector for a member.
Why I can’t use more than one Custom Attribute on a member ? And how I can make it possible ?
I’m assuming Min and Max are custom attributes that are dealt with by PropertyDrawer.
You can only have ONE PropertyDrawer affiliated attribute on a field. And if the type of that field uses a PropertyDrawer, only one is used.
This is just the way that PropertyDrawers work.
SerializeField is not a PropertyDrawer attribute.
Nor is Tooltip, Header, and a few other unity specific attributes. And of course any .Net attributes aren’t either.
I did not like this myself, so I wrote my own custom editor to deal with this… but it is NOT trivial.
You can see it here:
Editor entry point:
That references around a lot to several classes to work correctly, and requires reflecting out a lot of internal classes from Unity themselves.
And even with it, there are ramifications to stacking PropertyDrawers… only drawers that logically work with one another can stack.
I know the Range Attribute. Use both Min and Max is only for my example. But use them separately is better than a Range. If you make a Range(0.0f, Mathf.Infinity), you’ll have a useless slider.
Thanks for your answer, I’ll check your scripts later