Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

PreferenceItem is deprecated. Use [SettingsProvider] instead ...

Discussion in '2018.3 Beta' started by hippocoder, Sep 12, 2018.

  1. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,844
    PreferenceItem is deprecated. Use [SettingsProvider] instead
    UnityEditor.SettingsWindow:OpenUserPreferences()

    Would like this nugget to not annoy my console which I actually use for my own dev ;)
     
    RyanJEC likes this.
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    1,665
    So use [SettingsProvider] instead?
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,844
    I would, but it's your code doing it, not mine. Happens every compile from something in 2018.3 / HDRP 3.0
     
    LeonhardP, MihaPro_CarX and wojwen like this.
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    1,665
  5. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    790
    I'm getting the same error and I'm not using the Post Processing package.

    It started happening after I opened the Preferences window and now it happens constantly on code compile.
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,844
    Yep, that sounds about right.
     
  7. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    1,665
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,844
    Just dock the new preferences and editor settings tab next to scene view, should do it each time its compiling from there on.
     
  9. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    1,665
    Can't reproduce.
     
  10. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Untitled-1.jpg Settings has the issue as well: Win7 64bit - 2018.3.0b3
     
    Last edited: Oct 2, 2018
  11. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Hi LeonhardP,

    we require examples how to use the [SettingsProvider] class for save/load stuff. The warning occur on several assets from the asset store now, because they use the preference settings to store Unity Editor Seettings.

    We also use the [PreferenceItem()] for our editor variables extensively.

    Code (CSharp):
    1.  
    2.         [PreferenceItem("ConsolE")]
    3.         public static void OnGUI() {}
    4.         [PreferenceItem("Compiler")]
    5.         public static void OnGUI() {}
    6.         [PreferenceItem("Amplify Texture 2")]
    7.         public static void OnGUI() {}
    8.         [PreferenceItem("DTK Splines")]
    9.         public static void OnGUI() {}
    10.        etc etc....
    11.  
    #pragma warning disable xxx. does not work because there is not value given for :
    Trying to register preference item: "Compiler". [PreferenceItem] attribute is deprecated. Use [SettingsProvider] attribute instead.

    Did you have a solution to suppress all these warning about [PreferenceItem]
    This is really annoying!
     
    Last edited: Sep 28, 2018
  12. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    27
    The goal of the warning was to boost user awareness of the new [SettingsProvider] API. We will remove the warning and mark [PreferenceItem] as obsolete instead. It will be less "in your face".
     
    Quatum1000 likes this.
  13. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    199
    I can't remember when it started but I'm getting it with Cinemachine:

    Trying to register preference item: "Cinemachine". [PreferenceItem] attribute is deprecated. Use [SettingsProvider] attribute instead.
     
  14. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    SettingsProvider based on UnityEditor. Can you provide a simple example to create an SettingsProvider.asset and load and save some fields? That would be very handy. Thank you.
     
  15. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    4,218
    LeonhardP likes this.
  16. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    739
    Thank you..
    Seems an ungly task to explore....
     
  17. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,303
    Pasting how to migrate your old [PreferenceItem] code in the most barebone way just in case someone want to get rid of the warning quickly :

    Code (CSharp):
    1. #if UNITY_2018_3_OR_NEWER
    2.     private class MyPrefSettingsProvider : SettingsProvider
    3.     {
    4.         public MyPrefSettingsProvider(string path, SettingsScopes scopes = SettingsScopes.Any)
    5.         : base(path, scopes)
    6.         { }
    7.  
    8.         public override void OnGUI(string searchContext)
    9.         {
    10.             MyOldPrefCode();
    11.         }
    12.     }
    13.  
    14.     [SettingsProvider]
    15.     static SettingsProvider MyNewPrefCode()
    16.     {
    17.         return new MyPrefSettingsProvider("Preferences/MyPref");
    18.     }
    19. #else
    20.     [PreferenceItem("MyPref")]
    21. #endif
    22.     static void MyOldPrefCode()
    23.     {
    24.         EditorGUI.BeginChangeCheck();
    25.         ....
    26.     }
    27.  
     
    Last edited: Oct 11, 2018
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,844
    Hopefully Unity will update as well :D
    Mine comes from "UnityEditor.SettingsWindow:OnEnable()"
     
    fogsight likes this.
  19. z3nth10n

    z3nth10n

    Joined:
    Nov 23, 2013
    Posts:
    39
    Thanks, I used it on Zios Theme Editor: https://github.com/z3nth10n/unity-themes/commit/d2a3de9ab931e23e55ecd8eb7909cd706f28b585