How to set Dirty of Player Settings?

Hi there!

I using Unity 6 and I would like to
set game version or player settings parameters by code

like
PlayerSettings.Android.bundleVersionCode += 1;
or something like this

and after I call this script the PlayerSettings.Android.bundleVersionCode has actually changed,

But if I Ctl+S for save, all the player settings are restore back to before!
such as

if bundleVersionCode is 10 and change to 11 by script
and after Ctl+S bundleVersionCode will back to 10 again,

so I think it should set dirty or something
But I don’t know where or what object to SetDirty

anyone has any suggestion?
Thanks!!!

There is an internal SetDirty function in PlayerSettings. No idea if it’ll actually make the change stick - usually in Unity forgetting to set dirty makes values not save, it doesn’t revert them, so I suspect something else is happening.

Anyway, you can try reflection:

PlayerSettings.Android.bundleVersionCode += 1;
typeof(PlayerSettings).GetMethod("SetDirty", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
1 Like

Thank you very much, I will try!

Wow it actually works! I never write a script like this before

I stumbled upon this thread during my own issue incrementing the bundle version code from script for Android during the build process. I was explicitly setting the bundle version code based on some date logic so it’s always increasing and I was seeing it being properly updated via debug lines during the build process, but after checking the player settings in the build profile it was never actually updated. It was always staying at 1.

After a ton of research and debugging to no avail, I finally figured out by some fluke that it would not persist if the value was 1 originally. It seems like a Unity bug, so I thought I would post it here so it can be fixed for others. Once I set the value to 2 my build processing script was finally working properly.