Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Settings Manager 2.0.1: how to add to "Project Settings" instead of "Preferences"?

Discussion in 'Editor & General Support' started by Dev-4U, Jan 15, 2022.

  1. Dev-4U

    Dev-4U

    Joined:
    Nov 2, 2021
    Posts:
    23
    I'm struggling with the Settings Manager 2.0.1 package in Unity 2019.4.34f1. I downloaded the Samples 1.0.3 and see that even where the SettingsScope.Project is used, those settings always appear under Preferences, but never under Project Settings. :(

    I tried changing the k_PreferencesPath in case the "Preferences" part has a special meaning, but all it does is create a new subfolder under Preferences. That's what it looks now:

    upload_2022-1-15_13-18-0.png

    Here's my SettingsProvider using the UserSettingsProvider with Manager & Wrapper essentially the same as in Samples. Again: even in the Samples I can't get any of the settings to appear under Project Settings.

    Code (CSharp):
    1.     internal static class MySettingsProvider
    2.     {
    3.         const string k_PreferencesPath = "Project Settings/MY CUSTOM Settings";
    4.  
    5.         [UserSetting("displayCategory", "test int")]
    6.         static MySetting<int> TestInt = new MySetting<int>("testing an int", 11, SettingsScope.Project);
    7.  
    8.         [SettingsProvider]
    9.         static SettingsProvider CreateSettingsProvider()
    10.         {
    11.             var assemblies = new[] { typeof(MySettingsProvider).Assembly };
    12.             var provider = new UserSettingsProvider(k_PreferencesPath, MySettingsManager.Instance, assemblies);
    13.             return provider;
    14.         }
    15.     }
    So ... how do I add settings to Project Settings rather than Preferences with the Settings Manager package? Am I missing a simple thing here, or is this a bug in Settings Manager not respecting the SettingsScope?

    PS: the regular SettingsProvider does work with Project Settings just fine but I wanted to use UserSettingsProvider specifically so I don't have to write GUI code.
     
    Last edited: Jan 15, 2022
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,904
    My advice: install the ShaderGraph package (this has one of the simplest project settings page), open the following file
    Packages/Shader Graph/Editor/ShaderGraphProjectSettings.cs
    (you look for it in the project window and double click it, simply) in your code editor and check what they are doing. Copy the code and change it to your needs.
     
    Dev-4U likes this.
  3. Dev-4U

    Dev-4U

    Joined:
    Nov 2, 2021
    Posts:
    23
    Thanks for the tip, I'll check that out!
    Update: unfortunately SG also adds settings to Preferences even though the scope is set to Project. The file is also named accordingly: ShaderGraphPreferences.

    Also, in case anyone knows: how can I add a tooltip to a [UserSetting] field? The [Tooltip] attribute doesn't seem to work with UserSettingsProvider.
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,904
    I see this:
    screenshot.png

    screenshot1.png

    Snippet from the file:
    Code (CSharp):
    1.         [SettingsProvider]
    2.         public static SettingsProvider CreateShaderGraphProjectSettingsProvider()
    3.         {
    4.             var provider = new ShaderGraphProjectSettingsProvider("Project/ShaderGraph", SettingsScope.Project);
    5.             return provider;
    6.         }
     
  5. Dev-4U

    Dev-4U

    Joined:
    Nov 2, 2021
    Posts:
    23
    Hmmm we're probably not using the same version? I have SG 7.7.1 installed in Unity 2019.4 and there's no *ProjectSettings file, only the *Preferences one.
     
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,904
    I have the
    12.1.3
    , 2021.2.
     
  7. Dev-4U

    Dev-4U

    Joined:
    Nov 2, 2021
    Posts:
    23
    Got it from Unity 2020 and adapted it to my needs. Thanks for the tip!

    Also: quite a shame that SettingsManager doesn't (seem to?) support Project Settings. After all it's much less boilerplate code and less likely to break since there's no property access by string. OTOH I can now add tooltips to my settings! Can't believe SettingsManager won't do that either. :(
     
  8. Michael-Ryan

    Michael-Ryan

    Joined:
    Apr 10, 2009
    Posts:
    184
    I just started playing with the Settings Manager 2.01 package when I came across this post.

    The
    UserSettingsProvider
    does allow the settings to appear in Project Settings, but the code will always default to Preferences, and the documentation doesn't mention any way to override that.

    Constructor signature:

    Code (CSharp):
    1. public UserSettingsProvider(string path, Settings settings, Assembly[] assemblies, SettingsScope scopes = SettingsScope.User)
    Note that the
    UserSettingsProvider
    constructor has a default value for the
    scopes
    parameter. If you instead pass
    SettingsScope.Project
    , you'll end up with your settings appearing in the Project Settings window and not in Preferences.

    Defaults to Preferences:

    Code (CSharp):
    1. var provider = new UserSettingsProvider(k_PreferencesPath, MySettingsManager.Instance, assemblies);
    Places it in Project Settings:

    Code (CSharp):
    1. var provider = new UserSettingsProvider(k_PreferencesPath, MySettingsManager.Instance, assemblies, SettingsScope.Project);
     
    CodeSmile likes this.
  9. Michael-Ryan

    Michael-Ryan

    Joined:
    Apr 10, 2009
    Posts:
    184
    Also, there's a similar issue with
    UserSettingAttribute
    and the default
    tooltip
    parameter.

    Code (CSharp):
    1. public UserSettingAttribute(string category, string title, string tooltip = null)
    The documentation fails to mention the default parameter, so you'd have to look at the code to see it.

    Defaults to a null tooltip:

    Code (CSharp):
    1. [UserSetting("CATEGORY", "TITLE")]
    Has a tooltip:

    Code (CSharp):
    1. [UserSetting("CATEGORY", "TITLE", "This is a tooltip")]
     
    CodeSmile likes this.