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

How to reload Project Settings in UnityEditor

Discussion in 'Editor & General Support' started by KorStrix, Apr 30, 2021.

  1. KorStrix

    KorStrix

    Joined:
    Oct 17, 2015
    Posts:
    2
    Before building, I want to build after modifying various Unity-Setting files including Project Settings in the script through the argument values received from the command line.

    I tried the following, but it didn't work.

    AssetDataBase.ImportAsset(setting file path)
    AssetDataBase.Refresh()
    The api seems to work only for Assets and Packages.

    If this is currently impossible, there seems to be the only way to hardcode all values you want to control with the command line by value.
     
    cmersereau likes this.
  2. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    Bump. My team would like to be able to change project settings files as a build configuration strategy, but changing them while Unity is open doesn't affect the settings that are in use. Being able to change those files and refresh to force them to be used is what we are looking for.
     
  3. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
    I wrote some code to commit and update version number automatically. But it seems I have to switch out, focus to another window and swtich back to UnityEditor to make it reload ProjectSettings.asset.
    We need the feature too.
     
  4. javierfed

    javierfed

    Joined:
    Apr 10, 2015
    Posts:
    50
    I found that forcing a script reload can do the trick (
    Code (CSharp):
    1. EditorUtility.RequestScriptReload();
    ), but it seems a bit excessive. is there a simple way to reload the window without recompiling?
     
    yukunlinykl likes this.
  5. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    How reliable is that function? We starting using
    AssetDatabase.SaveAssets();
    and
    AssetDatabase.Refresh()
    calls, which normally work but there are times when the editor gets into a funky state and doesn't reload the settings properly. We haven't been able to determine why it doesn't work properly sometimes, but it seems to happen after a session in which settings files have been swapped multiple times.
     
    planternfish likes this.
  6. javierfed

    javierfed

    Joined:
    Apr 10, 2015
    Posts:
    50
    found that this works to update the ui, but it actually doesn't mark it as modified. using any sort of save on the project won't save the settings either. closing and reopening the project doesn't save it and the settings will revert. what gives? still having to click the ui to save the setting changes.