Search code examples
unity-game-engineprebuild

How to set Unity SplashScreen Logo in Prebuild


We are trying to programatically generate and set the Unity SplashScreen for Android and iOS.

The code below works when called from Unity [MenuItem("VoodooSauce/TEST")] but doesn't work when called from IPreprocessBuildWithReport-OnPreprocessBuild or RegisterBuildPlayerHandler ...

PlayerSettings.SplashScreen.logos = new[] {PlayerSettings.SplashScreenLogo.Create(3f, splashScreenSprite)};

We dynamically generate the "splashScreenSprite" and can successfully save it as a PNG.
We can even reload this PNG file as a Sprite.

However, regardless of what we do, the SplashScreen.logos code does not work ...

Strangely, regardless of where we call our code, it always updates the other fields in PlayerSettings.SplashScreen such as BackgroundColor, etc.


Solution

  • I ran into this issue as well. The thing that worked for me, was to make sure I saved the generated sprite as an asset to disk.

    After generating the texture, and using Sprite.Create() to create the sprite object itself, I called AssetDatabase.CreateAsset() (after deleting the last one if it still existed.) I followed up with a call to AssetDatabase.SaveAssetIfDirty() just to ensure it got written to disk.

    Then, in my IPreprocessBuildWithReport, updating the logos just like you did, worked.

    Hope this helps.