-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request/Question] How to make a "Required" attribute #4
Comments
Hi! There is no easy way to create your own attributes right now. I thought that you could do something like this with a decorator drawer https://docs.unity3d.com/ScriptReference/DecoratorDrawer.html , but you'll need access to the SerializedProperty and I don't think you can get it there. The easy way to achieve this would be to write a custom property drawer https://docs.unity3d.com/ScriptReference/PropertyDrawer.html that draws the property as is, and if it's null adds a warning below. This won't work for the properties that have some another custom property drawer, because each property can have only one drawer. But otherwise it is an ok solution, if Required is all you need. I'll think about adding validation functionality like this to MarkupAttributes, though. On the one hand it seems like a useful and appropriate feature, but on the other, I want to keep the project small. |
Thanks for the explanation! This is working for me now, albeit crudely. My custom drawer overrides OnGUI, and it logs an error to the console if the SerializedProperty's objectReferenceValue is null. It would be great if this were built-in, but I can understand why you'd want to keep the project small. Either way, thanks for the help. |
You can also use https://docs.unity3d.com/ScriptReference/EditorGUI.HelpBox.html to display a warning in the editor, like in Odin. Depending on message type it will show a warning or an error icon next to your message. |
I've been using Markup Attributes for a while now, and it's been great. I still have Odin in my project, but the only time I ever use it is for the Required attribute: https://odininspector.com/attributes/required-attribute
Are there any plans to add something like this to Markup Attributes? If not, is there any way for us to create our own attributes?
The text was updated successfully, but these errors were encountered: