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

Unity2D相机堆栈报错:Camera不匹配输出属性,分辨率适配异常求助

解决Unity2D相机堆栈「Camera do not match the output properties」报错思路

针对主相机与UI相机分辨率不匹配导致的报错,且临时修复仅生效一次、特定分辨率正常的问题,可尝试以下方案:

  • 强制同步相机输出属性
    编写Editor脚本,在编辑模式下自动同步主相机与UI相机的关键属性(宽高比、像素矩形、目标显示器),避免切换分辨率后手动调整。示例代码:

    using UnityEditor;
    using UnityEngine;
    
    [CustomEditor(typeof(Camera))]
    public class CameraSyncEditor : Editor
    {
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            Camera targetCam = (Camera)target;
            if (GUILayout.Button("Sync with Main Camera"))
            {
                Camera mainCam = Camera.main;
                if (mainCam != null)
                {
                    targetCam.aspect = mainCam.aspect;
                    targetCam.pixelRect = mainCam.pixelRect;
                    targetCam.targetDisplay = mainCam.targetDisplay;
                    EditorUtility.SetDirty(targetCam);
                }
            }
        }
    }
    
  • 统一相机渲染路径与输出目标
    确保主相机和UI相机的Render Path完全一致(如均设为Forward);若使用了Target Texture,将其分辨率设为动态匹配Game视图,不要固定尺寸。

  • 动态适配UI相机参数
    将UI相机设为正交投影,通过代码动态计算Orthographic Size以匹配屏幕分辨率:

    void UpdateCameraSize()
    {
        float baseHeight = 1080f; // 你的基准设计高度
        float scale = Screen.height / baseHeight;
        GetComponent<Camera>().orthographicSize = 5f * scale; // 5为基准Size,按需调整
    }
    

    同时将Canvas设为Screen Space - Camera模式并绑定UI相机,确保UI随相机同步适配。

  • 重置Game视图分辨率配置
    删除自定义分辨率预设,重新创建对应设备的分辨率,确保预设宽高比与相机宽高比严格匹配;关闭Game视图的Maximize on Play选项,避免运行时强制拉伸引发冲突。

  • 检查相机深度与清除标志
    将UI相机的Depth设为高于主相机,清除标志设为Depth Only,避免渲染冲突导致属性检测异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 13:57:26