Can Enums be saved as strings?

NodeCanvas Forums Custom Nodes & Tasks Can Enums be saved as strings?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16959
    johnrgeraci
    Participant

    I currently have a number of custom actions and conditionals that are bound to our in-game data.  Specifically, I allow the designers to pick from specific enums using BBParameter<enumType> enumChoice;

    This works fine, except when I need to change the defined enums.  For instance, I wanted to delete the first choice which was None as that case cannot exist and confuses our designers.

    If I look at the saved .asset file, I see this: “abilityOption”:{“_value”:1} which when I change what 1 means, it causes the wrong choice.  Is there any way for these to be saved as a string?

    I usually use [JsonConverter(typeof(StringEnumConverter))] which when I Deserialize and Serialize json files, the enum names are preserved.

    Is there a mode that will allow the asset files to save enums as their string equivalents?

    Thanks.

    #16967
    johnrgeraci
    Participant

    To answer my own question:  Yes, there is a setting within the nodeCanvas package that saves enums out as strings.  It’s in fsGlobalConfig.cs:

    ///<summary> Enums are serialized using their names by default. Setting this to true will serialize them as integers instead.</summary>
    public static bool SerializeEnumsAsInteger = true;

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.