Set Player Settings Preset via Editor Script

Hello!
I have two presets for Player Settings.
Now I want to change the Player Settings preset via Editor script.
I know I have the method of Preset.ApplyTo(Object o), but I don’t know how can I get the Instance Object of PlayerSettings in order to inject it into this method.

Someone knows how?
Thanks

Hi
I wrote this code:

var playerSettings = FindObjectOfType<PlayerSettings>(true);
var isSuccess=preset.ApplyTo(playerSettings);
AssetDatabase.RefreshSettings();

The preset.ApplyTo returns true, but the Player Settings does not change… any suggestions?

Hey! Did you figure this out? Im implementing something similar as well

Preset preset = AssetDatabase.LoadAssetAtPath<Preset>(presetPath);
var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>()[0];
if (preset != null)
{
    bool success = preset.ApplyTo(playerSettings);
    Debug.Log("Settings status: "+success);
    //AssetDatabase.SaveAssets();
    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(playerSettings));
}
else
{
    Debug.LogError("Preset not found at path: " + presetPath);
}

tried this, no luck either

Preset preset = AssetDatabase.LoadAssetAtPath<Preset>(presetPath);
var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>()[0];
if (preset != null)
{
    bool success = preset.ApplyTo(playerSettings);
    Debug.Log("Settings status: "+success);
    AssetDatabase.Refresh();
    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(playerSettings));
}
else
{
    Debug.LogError("Preset not found at path: " + presetPath);
}

This worked. Give it a try.

1 Like

I had to do something similar to @abhishikdtlabz, but then search for a full list of PlayerSettings, not just the first found:

      var targets = Resources.FindObjectsOfTypeAll<PlayerSettings>();

      foreach (var target in targets)
            {
                if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target)))
                {
                    continue;
                }

                if (preset.ApplyTo(target))
                {
                    AssetDatabase.Refresh();
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
                    Debug.Log($"Successfully applied preset to {target.name}");
                }
            }
1 Like