Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Modifying Enumerator Values via Inspector Prior to Runtime

Discussion in 'Editor & General Support' started by Joewa654321_, Jun 27, 2022.

  1. Joewa654321_

    Joewa654321_

    Joined:
    Apr 27, 2020
    Posts:
    32
    Hi all,

    I have a question regarding the possibility of modifying the contents of an enumerator using the inspector window. I want to store accessible controls/settings as an enumerator value to determine what control/setting is being referenced when I make calls in game, but for ease of use I'd like to pair the contents of a database that stores scriptable objects in an array to the available enumerator values. These scriptable objects store common data that is specific to settings/controls such as the enumerator value as a variable to dictate what input/setting is being called (To be clear, settings and controls are separate but I want to utilize the same concept for both).

    Currently, I define the enumerator values as well as the database and setting/input objects manually but I wanted to see if I could link/modify the contents of the enumerator prior to run-time based on the contents of the scriptable object array on the database using something like OnValidate(). The name for each enumerator value would be derived from a string variable on the scriptable objects. Does anyone have any suggestions or Unity documentation links for accomplishing something like this? Or even if it is not possible/recommended, I would appreciate any insight.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
  3. Joewa654321_

    Joewa654321_

    Joined:
    Apr 27, 2020
    Posts:
    32
    Yes, Enums/Enumerations, for example I represent my GameInputs like this:

    Code (CSharp):
    1.  
    2. enum GameInput
    3. {
    4.     PrimaryAction,
    5.     SecondaryAction,
    6.     MoveForward,
    7.     MoveBackward,
    8.     MoveLeft,
    9.     MoveRight
    10. }
    11.  
     
  4. Joewa654321_

    Joewa654321_

    Joined:
    Apr 27, 2020
    Posts:
    32
    In case my question was poorly worded, put simply I want to alter the values within my Enum prior to runtime based on what is stored in an array found on a database defined in the inspector. The context is that I am allowing users to declare their in-game inputs via this database but I do not want to have to modify/update the Enum seperately and would prefer it to be a single, straight forward process.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    There is no way to modify the source code via database entries. You must simply go with a data-driven approach rather than using the enum.