- Home /
Updating Player Settings with code
Hi everyone! I have a trouble with updatings player settings with my editor script. I have 4 versions of my game with different settings (Android free, android paid, iOS free, iOS paid) All versions have different Product names, bundle ids and icons. The problem is that when I update icons with my code and try to build a game, the icons appear to be unassigned, even though all icons are correclty set in editor after script execution.
Here's the code that changes the icons:
static void SetApplicationIcon(BuildTargetGroup platform, bool isPaid)
{
Texture2D[] iconSet;
int[] num ;
if (platform == BuildTargetGroup.Android) {
iconSet = new Texture2D[5];
num = new int[] {144, 96, 72, 48, 36};
} else if (platform == BuildTargetGroup.iPhone) {
iconSet = new Texture2D[7];
num = new int[] {152, 144, 120, 114, 76, 72, 57};
} else {
Debug.LogError("Switch to ANDROID or IOS platform");
return;
}
for (int i = 0; i < num.Length; i++) {
int n = num[i];
if (isPaid) {
Texture2D icon = new Texture2D(n, n);
icon.LoadImage(File.ReadAllBytes(Application.dataPath + "/Icon/Icon_" + n.ToString() + ".png"));
iconSet[i] = icon;
} else {
Texture2D icon = new Texture2D(n, n);
icon.LoadImage(File.ReadAllBytes(Application.dataPath + "/Icon/Free/Icon_" + n.ToString() + ".png"));
iconSet[i] = icon;
}
}
PlayerSettings.SetIconsForTargetGroup(platform, iconSet);
}
I've found out that when I press "Build" button and then cancel it right away, the icons are already unassigned in Player settings.
If I set icons with mouse by drag'n'dropping, then the icons are set properly.
How to tell Editor to remember the icons? Thanks in advance!
Answer by artman_12 · Aug 13, 2014 at 03:16 PM
I've fixed it by moving icons into the Resources folder and loading them with
icon = Resources.Load("Icon/Icon_" + n.ToString()) as Texture2D;
instead of
icon.LoadImage(File.ReadAllBytes(Application.dataPath + "/Icon/Free/Icon_" + n.ToString() + ".png"));
Answer by digitspro · Sep 09, 2020 at 09:23 PM
I had the same issue. I was loading the Texture2D by reading the file bytes myself into a new Texture2D. I fixed it by simply loading the Texture2D using AssetDatabase.LoadAssetAtPath. I did not want to solve it by using Resources.Load because I am worried that putting the icons there will increase the size of the final build file (I build for Android).
Your answer
Follow this Question
Related Questions
Gizmos icons 0 Answers
How to set ProjectSettings via script 1 Answer
Undo.RecordObject isn't working. 7 Answers
Can you run custom code when changing scene perspective? 1 Answer