You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity命令行构建后Addressable TMP字体无法渲染问题

问题描述

我使用Makefile自动化Unity游戏的构建与上传,Makefile代码如下:

unity: unity_win unity_mac unity_tux
unity_win:
    $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildWindowsPlayer .$(BUILD_DIR)/win/game.exe -logFile $(BUILD_LOG)/mac.log
unity_mac:
    $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildOSXUniversalPlayer .$(BUILD_DIR)/mac/game.app -logFile $(BUILD_LOG)/win.log
unity_tux:
    $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildLinux64Player .$(BUILD_DIR)/tux/game -logFile $(BUILD_LOG)/tux.log

直接通过Unity编辑器(Unity->Build Settings->Build)构建游戏时一切正常,但使用该脚本生成的可执行文件时,所有Addressable场景中的字体均无法渲染:Mac端显示空白,Windows/Linux端显示紫色矩形。此问题是在集成Addressable后出现的,且可寻址与不可寻址场景使用的是相同的默认Text Mesh Pro字体。

解决方案
  • 先执行Addressables构建,再做平台打包
    Unity编辑器构建会自动触发Addressables内容构建,但批处理模式下需要手动调用。修改Makefile,在平台构建前添加Addressables构建步骤,同时修正原脚本中日志文件路径的错误:

    unity: build_addressables unity_win unity_mac unity_tux
    
    build_addressables:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -executeMethod UnityEditor.AddressableAssets.Scripting.AddressableAssetSettings.BuildPlayerContent -logFile $(BUILD_LOG)/addressables.log
    
    unity_win:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildWindowsPlayer .$(BUILD_DIR)/win/game.exe -logFile $(BUILD_LOG)/win.log
    unity_mac:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildOSXUniversalPlayer .$(BUILD_DIR)/mac/game.app -logFile $(BUILD_LOG)/mac.log
    unity_tux:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildLinux64Player .$(BUILD_DIR)/tux/game -logFile $(BUILD_LOG)/tux.log
    
  • 匹配Addressables构建目标与平台
    打开Addressables Groups窗口,确认Build Target和批处理构建的平台一致;如果需要多平台打包,要为每个平台单独执行Addressables构建,示例:

    unity: build_addr_win build_addr_mac build_addr_tux unity_win unity_mac unity_tux
    
    build_addr_win:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildTarget Windows -executeMethod UnityEditor.AddressableAssets.Scripting.AddressableAssetSettings.BuildPlayerContent -logFile $(BUILD_LOG)/addressables_win.log
    build_addr_mac:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildTarget macOS -executeMethod UnityEditor.AddressableAssets.Scripting.AddressableAssetSettings.BuildPlayerContent -logFile $(BUILD_LOG)/addressables_mac.log
    build_addr_tux:
        $(UNITY_LOCATION) -quit -batchmode -projectpath ./project -buildTarget Linux -executeMethod UnityEditor.AddressableAssets.Scripting.AddressableAssetSettings.BuildPlayerContent -logFile $(BUILD_LOG)/addressables_tux.log
    
  • 检查TMP字体的Addressables配置

    • 确认默认TMP字体已添加到Addressables Groups中,Label和Group配置无误
    • 检查字体的Load Path设置,确保打包后能被正确寻址
    • 不要将字体同时设置为可寻址和场景嵌入,避免加载冲突
  • 通过日志定位问题
    查看Addressables构建日志和平台构建日志,搜索error或warning关键词,排查资源打包失败、路径错误等具体问题。

内容的提问来源于stack exchange,提问作者Rose

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 14:38:29