Skip to content

feat: add option to remove from preloadedAssets when build player#267

Open
Magicqy wants to merge 1 commit intomob-sakai:mainfrom
Magicqy:main
Open

feat: add option to remove from preloadedAssets when build player#267
Magicqy wants to merge 1 commit intomob-sakai:mainfrom
Magicqy:main

Conversation

@Magicqy
Copy link
Copy Markdown

@Magicqy Magicqy commented Apr 8, 2026

Description

Add Exclude From Preloaded Assets When Build Player option to support AssetBundle / Addressables hot-update workflows.

When enabled, the settings asset is temporarily removed from PlayerSettings.preloadedAssets during Player Build only, so it is NOT included in the built player. The asset remains in PreloadedAssets during normal Editor operation — all original auto-create, auto-register, and singleton behaviors are completely unchanged.

At runtime, shaders loaded from AssetBundles cannot be found via Shader.Find(). To address this, shader references are extracted from the ShaderVariantCollection at edit-time and serialized into a flat List<Shader>. At runtime, FindShaderByName() resolves shaders from this list first, falling back to Shader.Find() only when no match is found. Additionally, Shader.Find() calls in TerminalMaskingShape.cs and SoftMaskUtils.cs are replaced with FindShaderByName() for consistency.

How it works

  1. Editor: Settings always stay in PreloadedAssets. Zero behavioral difference from upstream.
  2. PreprocessBuild (callbackOrder=-1): Sets s_BuildingPlayer = true, removes excluded settings from PreloadedAssets, logs the action.
  3. PreprocessBuild (callbackOrder=0, original): Calls Initialize(). The s_BuildingPlayer guard prevents SetDefaultSettings() from restoring PreloadedAssets.
  4. Build proceeds: Any AssetPostprocessor or instance getter that triggers SetDefaultSettings() is also guarded.
  5. PostprocessBuild (callbackOrder=-1): Sets s_BuildingPlayer = false, calls Initialize() to restore PreloadedAssets, logs the action.

Changed files

  • PreloadedProjectSettings.cs — new m_ExcludeFromPreloadedAssetsWhenBuildPlayer field, s_BuildingPlayer static flag, ExcludeFromBuild inner class (IPreprocessBuildWithReport + IPostprocessBuildWithReport), guard in Initialize() and instance getter
  • ShaderVariantRegistry.csm_RegisteredShaders field, InitializeShaderLookup(), FindShaderByName(), SyncRegisteredShaders()
  • UISoftMaskProjectSettings.cs — call InitializeShaderLookup() in OnEnable
  • UISoftMaskProjectSettingsEditor.cs — expose the new option and registered shaders list in Inspector
  • TerminalMaskingShape.cs / SoftMaskUtils.cs — use FindShaderByName() instead of Shader.Find()
  • CHANGELOG.md / README.md — document the new feature

Type of change

  • New feature (non-breaking change which adds functionality)

Test environment

  • Platform: Editor (Windows), Android
  • Unity version: 2022.3 LTS
  • Build options: IL2CPP, .NET Standard 2.1

Checklist

  • This pull request is for merging into the develop branch
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked my code and corrected any misspellings

@Magicqy Magicqy requested a review from mob-sakai as a code owner April 8, 2026 13:33
@Magicqy Magicqy force-pushed the main branch 5 times, most recently from a9601b4 to 221db98 Compare April 9, 2026 09:10
@Magicqy Magicqy changed the title feat: add option to disable auto add to preloadedAssets feat: add option to remove from preloadedAssets when build player Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant