- Home /
Programmatically set default icon for mobile
Is there a way to do this? I see PlayerSettings.SetIconsForTargetGroup() but it would much easier to reset the default icon.
There doesn't seem to be a way to set the splash screen either.
Answer by kromenak · Apr 04, 2012 at 06:30 PM
It would be great if Unity provided variables for these elements, but as it stands I don't think you can change the icon in that way.
What we do is, say, have a folder named "Device/Icons" and "Device/Splash" where we have the icons and splash screen images. You can then drag these elements in the inspector to assign them as appropriate. You can then use the AssetDatabase.Copy command to overwrite these assets with other assets based on the particular build you are trying to create. For example, if you are using splash.png for your splash screen, you might do
AssetDatabase.CopyAsset("Assets/Christmas/Splash/splash.png", "Assets/Device/Splash/splash.png");
if you were creating a Christmas build. This doesn't change the asset assigned in the inspector, but it effectively modifies the existing asset to change it.
EDIT: As mentioned in comments, this copy method could avoid some asset database confusion:
FileUtil.CopyFileOrDirectory("Assets/Christmas/Splash/splash.png", "Assets/Device/Splash/splash.png");
AssetDatabase.Refresh();
That sucks. The main thing I was trying to achieve was building various versions of the app with one click. (We have a flash card app with like 5 different sets). That might work, though. Just using a generic splash.png/icon.png and replacing them and then building.
Unfortunately copying over an existing file deselects it from the inspector. Any other work arounds?
FileUtil.CopyFileOrDirectory() and then AssetDatabase.Refresh() is the correct way to do this. The asset database seems confused otherwise. You should modify your answer :)
Answer by The-Bacon-Baron · Dec 16, 2012 at 11:55 PM
You can do this! Use this:
PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, theTexture2DArray);
Where theTexture2DArray is an array of the Texture2D asset you want to be the icon.
This will set the default icon from the player settings, and if there aren't overrides for the platform icons, those will change also.
Hope this helps!
Glad to know this works now. Back when I asked this question it did not.
Answer by cowlinator · Feb 05, 2014 at 12:32 AM
I don't believe there is a way to change the default icon through script, but this is what i do.
Texture2D icon = Resources.Load(iconName) as Texture2D;
Texture2D[] icons = new Texture2D[]{icon, icon, icon, icon};
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons);
Answer by sama-van · Dec 12, 2019 at 09:27 AM
However the FileUtil.CopyFileOrDirectory() log an error if the file already exists. Also better the assets path to be absolute :
Here is what I do :
string _defaultPath = "/_MyAppFolder/Res/UI/_Common/Texture/Default_AppIcon.png";
string iconPath= "/_MyOtherAppFolder/Res/UI/_Common/Texture/OtherAppIcon.png";
FileUtil.DeleteFileOrDirectory(Application.dataPath + _defaultPath);
FileUtil.CopyFileOrDirectory(Application.dataPath + iconPath, Application.dataPath + _defaultPatht);
AssetDatabase.Refresh();
FileUtil.Replace(source, destination) is a simpler way of doing that