[SUGGESTION] Default and Constraints for ValueDropdown (and more?)

Issue #478 closed
Justin Hughart created an issue

I'm trying to emulate Tag-like behavior using Odin. Currently I'm doing the following.

    [Tooltip("The ID of the position you want to change to.")]
    public string DesiredPosition;

I would like to constrain DesiredPosition to a proper value of the List<string> returned from ValueDropdown, and this also means adding a default for it to start at. I've looked all over and I can't seem to find anything about it. To be clearer about the requirements I'm looking for...

-If DesiredPosition is "", which is what it is at the start, get the list above and set it to item 0. -Check if DesiredPosition's value is on the list. If it is not, set it to the default value, item 0.

I could do this via code, but I believe both of these things should be part of the ValueDropdown attribute, or another attribute designed to work with ValueDropdown. Thank you for your time.

Comments (3)

  1. Bjarke Elias
    • changed status to open

    Hello, thanks for the suggestion!

    I don't think I fully understand your question regarding constraints as you already have complete control over what values should be displayed dropdown. You can also assign custom names through ValueDropdownItems if you want the "" value to have a proper name.

    Regarding default values, do you mean that you want to assign a value automatically if the value is ""? Because there is no good way of doing that though an attribute, as it's something that would only be applied if you're looking at the object in the inspector, so it's not guaranteed. The best way of achieving that would be to implement ISerializationCallbackReciever and modify the value in OnDeserialized.

  2. Justin Hughart reporter

    Yeah, I had talked to Tor on Discord in depth about it after I posted it, and we talked about the problems with it. I didn't realize at the time how much of a pain it'd be. I still feel like there's gotta be a good way somehow to deal with this through an attribute, but this is by no means a trivial problem, especially for something with so little gain. Someone would have to get an epiphany somewhere for this to really work... You could close this if you want, since this is a pretty major problem with no apparent solution that isn't problematic.

  3. Log in to comment