Hi guys! I'don't know if it's me or is a known bug, but UnityEngine.MinAttribute is not working for me on float and int variables. I have a variable declared like this: [MinAttribute(1)] public float something; Then in insepctor I'm able to set this value under 1, even by typing, scrolling or whatever. I'm using Unity 2019.2 atm. Thanks for any reply!
It's essentially a property drawer for numerical types as I understand it, so it's worth noting that it's not a validation attribute and won't stop the value from being under a certain amount programmatically, but rather just makes a visual restriction in the inspector. It won't apply if the inspector is in Debug mode (because that bypasses the editor script that applies property drawers entirely), and it won't apply if you're using a custom inspector (in some cases) or another property drawer for that property which isn't taking the Min attribute into account and takes precedence.
Hi Lysander, thanks for the answer! I'm not changing it via code, either in debug mode or custom inspector, just typing in its field via normal Inspector or dragging the field. Others attributes like [Range] are working properly.
You may not be referencing the MinAttribute that you think you are- be sure to check your namespaces and be sure that the UnityEngine.MinAttribute is the one being used. PostProcessing also (IIRC) has a MinAttribute which may interfere with this behaviour. Depending on the version of PostProcessing you have in your project, it may be worth looking into PostProcessing.MinDrawer to see if there's a conflict there as well.
Also checked, either having "using UnityEngine" as declaring the attribute like UnityEngine.MinAttribute :/ It smells like a bug like spirit
It does appear to be a bug- the associated PropertyDrawer class should theoretically be in this script, but as you can see it's absent. My advice is to use Range instead- if you need to, you can use int.MaxValue as the upper limit, but the drag increments are pretty massive at that level, and it doesn't protect against typed-in values. You can report it if you like- I couldn't find an existing report for it, but I didn't look that hard either. Alternatively, you can copy the RangeDrawer in that script I linked and paste it in your own file, change the type it draws for to the MinAttribute, and adjust it to look like whatever you want. =)
I have the same problem, it seems to be a bug. I also checked everything that Lysander said. Min() doesn't work at all.
You can see where we fixed it here: https://issuetracker.unity3d.com/is...of-a-variable-when-using-the-inspector-window