unity-2d-pixel-perfect
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseunity-2d-pixel-perfect — two components with the same name, and only one of them is yours
unity-2d-pixel-perfect — 两个同名组件,但只有一个是你需要的
Pixel perfect is not one Unity feature, it is two incompatible implementations of one name. URP ships, driven by enums. The standaloneUnityEngine.Rendering.Universal.PixelPerfectCamerapackage shipscom.unity.2d.pixel-perfect, driven by booleans. Adding the wrong one costs you nothing at compile time and everything at runtime, so the pipeline in force decides the component, and you resolve it first.UnityEngine.U2D.PixelPerfectCamera
Pixel perfect 并不是一项 Unity 功能,而是同一名称下两种互不兼容的实现。 URP 自带,由枚举驱动。独立的UnityEngine.Rendering.Universal.PixelPerfectCamera包自带com.unity.2d.pixel-perfect,由布尔值驱动。 添加错误的组件在编译期不会带来任何问题,却会在运行时造成所有问题,因此, 当前生效的管线决定使用哪个组件,而第一步就是解析它。UnityEngine.U2D.PixelPerfectCamera
Start here — symptom → where to look
从这里开始 — 症状 → 查看位置
| Symptom | Go to |
|---|---|
"Which | §1 |
| The component is on the camera and nothing snaps; it compiles but does nothing after a render-pipeline change | §1, §9 — wrong implementation for the pipeline |
| §1 — assembly names |
| Sprites are soft or washed out at every zoom | §2 |
| Sprites sharp at one zoom, soft at another; choosing a reference resolution | §3 — non-integer scale factor |
| Hairline gaps between tilemap tiles | §5 |
| Pixels crawl or shimmer while the camera pans | §4 |
| The camera jitters and framing pops between shots; Cinemachine and the pixel camera fight over orthographic size | §6 — Cinemachine |
| UI text went soft; the scene did not | §7 |
| Post-processing blurs the entire frame | §7 |
| A physics-driven sprite stutters while everything else is smooth | §8 |
| Black bars, or the scene stretched to a wrong aspect | §4 |
Compiler errors naming | §9 |
| Property tables, enum values, old-bool mapping | |
| 症状 | 查看位置 |
|---|---|
应该添加哪个 | §1 |
| 相机上已经挂载了组件,但没有任何吸附效果;能够编译,却在切换渲染管线后不起作用 | §1、§9 — 管线对应的实现错误 |
| §1 — 程序集名称 |
| Sprite 在任何缩放倍率下都显得模糊或发白 | §2 |
| Sprite 在某个缩放倍率下清晰,在另一个倍率下模糊;需要选择参考分辨率 | §3 — 非整数缩放系数 |
| Tilemap Tile 之间出现发丝般的缝隙 | §5 |
| 相机平移时像素爬行或闪烁 | §4 |
| 相机抖动,镜头切换时构图跳变;Cinemachine 与像素相机争夺 orthographic size | §6 — Cinemachine |
| UI 文本变软,但场景没有变软 | §7 |
| 后处理模糊了整个画面 | §7 |
| 由物理系统驱动的 Sprite 卡顿,而其他内容都很流畅 | §8 |
| 出现黑边,或场景被拉伸到错误的宽高比 | §4 |
编译错误提到 | §9 |
| 属性表、枚举值和旧布尔值映射 | |
1. Resolve the pipeline, then pick the component
1. 先解析管线,再选择组件
Read, notGraphicsSettings.currentRenderPipeline. The second holds the pipeline instance, which does not exist until a frame has rendered, so it reports "built-in" on startup paths and on headless checks. On a project running URP,RenderPipelineManager.currentPipelinecan be null whileRenderPipelineManager.currentPipelinenames the URP asset. Two APIs, opposite answers, same instant.GraphicsSettings.currentRenderPipeline
| URP | Standalone built-in | |
|---|---|---|
| Type | | |
| Assembly | | |
| Comes from | URP itself — nothing to install | |
| API shape | Enums: | Booleans: |
Confirm the standalone assembly name by reflection on a project that has the package —
§2, with why a guessed suffix breaks
and the lockfile check.
reference/pipeline-and-migration.mdRuntimeType.GetTypeDo not addto a URP project. It installs and compiles without complaint, and leaves the project carrying two different components under one name — remove the package rather than working out which one wins. On a URP project the type you want is already there; a project that arrived with the package already on a camera is §9.com.unity.2d.pixel-perfect
A null default pipeline does not mean built-in. A project can have an empty default with
every quality tier overriding it; folds the tier in and is the one to
trust. The six reads and the grep trap: §1; the full
procedure: → .
currentRenderPipelinereference/pipeline-and-migration.mdunity-render-urpreference/resolve-active-pipeline.mdCode: — pipeline probe,
component-type lookup for either pipeline, and the mismatch check §9 uses.
resources/PipelineDetection.csReport, then wait. Fixing import settings reimports textures and rewritesfiles across the art folder; adding or swapping a camera component changes a scene. Survey first, list what you would change with before/after values, and wait for confirmation. Default to the open scene — sweep the whole project only when asked for it..meta
Reaching a live Editor for any of these reads: → .
unity-debugreference/editor-control.md请读取,而不是GraphicsSettings.currentRenderPipeline。 后者保存的是管线 实例,该实例在渲染一帧之前并不存在,因此 在启动路径和 headless 检查中会报告为“built-in”。在运行 URP 的项目中,RenderPipelineManager.currentPipeline可能为 null,而RenderPipelineManager.currentPipeline则会给出 URP asset 名称。两个 API 在同一时刻会给出相反的答案。GraphicsSettings.currentRenderPipeline
| URP | 独立包(Built-in) | |
|---|---|---|
| 类型 | | |
| 程序集 | | |
| 来源 | URP 自身 — 无需安装 | |
| API 形式 | 枚举: | 布尔值: |
在已安装该包的项目中,通过反射确认独立包的程序集名称——
另请参阅 §2,了解猜测 后缀为何会导致
和 lockfile 检查失败。
reference/pipeline-and-migration.mdRuntimeType.GetType不要在 URP 项目中添加。 它安装和编译时都不会报错, 却会让项目同时携带两个同名但不同的组件——应当移除该包,而不是尝试判断哪个组件会生效。 在 URP 项目中,你需要的类型已经存在;如果项目中的相机原本就挂载了该包中的组件,请参阅 §9。com.unity.2d.pixel-perfect
默认管线为 null 并不意味着使用 Built-in。 项目可能将默认管线设为空,
但每个 quality tier 都覆盖了它; 会将 tier 的覆盖合并计算,
因此应以此为准。六种读取方式以及 grep 陷阱:参阅 §1;
完整流程: → 。
currentRenderPipelinereference/pipeline-and-migration.mdunity-render-urpreference/resolve-active-pipeline.md代码: — 包含管线探测、
两种管线的组件类型查找,以及 §9 使用的组件不匹配检查。
resources/PipelineDetection.cs先报告,再等待。 修改导入设置会重新导入纹理,并重写整个美术目录中的文件;添加或替换相机组件会修改场景。请先进行排查,列出准备更改的内容及前后值, 然后等待确认。默认只检查当前打开的场景;仅在用户明确要求时才扫描整个项目。.meta
如需在实时 Editor 中执行其中任何读取操作: → 。
unity-debugreference/editor-control.md2. The four import settings that decide sharpness
2. 决定清晰度的四项导入设置
Bilinear filtering is the import default and the most common cause of soft pixel art. Set
, mipmaps off, , one project-wide; AA 0 in
the active quality level, MSAA 1 on the URP asset, and //
off on the camera. A centre pivot on an odd-sized sprite lands on half a
pixel ("only this one sprite is blurry"). Editor grid snapping: . The table, the
why and the snapping steps: §2. Code:
. Frames shipped upscaled by F ( )
import at F × the art-pixel PPU; is their PPU ÷ F ( →
).
filterMode = PointUncompressedspritePixelsPerUnitallowHDRallowMSAAallowDynamicResolution1 / assetsPPUreference/sharpness.mdresources/SpriteImportFix.csframes.jsonpixel.block_pxassetsPPUcodex-visualreference/pixel-grid.md双线性过滤是默认导入设置,也是像素艺术发软最常见的原因。将
、关闭 mipmaps、使用 ,并为整个项目统一设置一个
;在当前生效的 quality level 中将 AA 设为 0,在 URP asset 中将
MSAA 设为 1,并关闭相机上的 //。
奇数尺寸 Sprite 使用中心 pivot 时会落在半个像素上(“只有这一个 Sprite 模糊”)。
Editor 网格吸附:。相关表格、原理和吸附步骤:
§2。代码:。
以 F 倍尺寸发布的帧( 中的 )应按 F × 美术像素 PPU 导入;
为其 PPU ÷ F( → )。
filterMode = PointUncompressedspritePixelsPerUnitallowHDRallowMSAAallowDynamicResolution1 / assetsPPUreference/sharpness.mdresources/SpriteImportFix.csframes.jsonpixel.block_pxassetsPPUcodex-visualreference/pixel-grid.md3. Reference resolution, chosen once
3. 只选择一次的参考分辨率
Pick it before art production: 320×180 fits 1080p, 1440p and 2160p at whole numbers (6×, 8×,
12×), which is why it is the safe default; a fractional factor ribs the art, and a screen with no
integer fit gets , not a stretch. (320×180 at PPU 16 → 5.625), separate from the component's own
read-only value. The table: §3.
cropFrame = WindowboxCamera.orthographicSize = (refResolutionY / 2f) / assetsPPUreference/sharpness.md在制作美术资源前选定参考分辨率:320×180 可分别以整数倍适配 1080p、1440p 和 2160p
(6×、8×、12×),因此是安全的默认值;非整数缩放系数会让画面出现波纹,
而无法与整数倍率匹配的屏幕应使用 ,而不是拉伸。
(320×180、PPU 16 → 5.625),该值与组件自身的只读值相互独立。
相关表格: §3。
cropFrame = WindowboxCamera.orthographicSize = (refResolutionY / 2f) / assetsPPUreference/sharpness.md4. gridSnapping
and cropFrame
gridSnappingcropFrame4. gridSnapping
与 cropFrame
gridSnappingcropFrameGridSnappingNonePixelSnappingUpscaleRenderTextureCropFrameNonePillarboxLetterboxWindowboxStretchFillPixelPerfectFilterModeRetroAAPointPixelSnappingWindowboxUpscaleRenderTexturehas no public property on the URP component. Only the serialized privatePixelPerfectFilterMode, so the Inspector can set it and script cannot — author it in a prefab or scene. It is documented to apply only underm_FilterMode, and it is unrelated to per-texturecropFrame = StretchFill(§2).filterMode
Property tables for both components, the old-bool mapping, recommended combinations and the
formula: .
pixelSnapSpacingreference/api-and-enums.mdGridSnappingNonePixelSnappingUpscaleRenderTextureCropFrameNonePillarboxLetterboxWindowboxStretchFillPixelPerfectFilterModeRetroAAPointPixelSnappingWindowboxUpscaleRenderTextureURP 组件上的没有公开属性。 它只有序列化私有字段PixelPerfectFilterMode,因此 Inspector 可以设置,而脚本不能设置——请在 prefab 或 scene 中预先配置。 文档说明它仅在m_FilterMode下生效,并且与单张纹理的cropFrame = StretchFill(§2)无关。filterMode
两个组件的属性表、旧布尔值映射、推荐组合和 公式:
。
pixelSnapSpacingreference/api-and-enums.md5. Tilemap seams — work the ladder in order
5. Tilemap 接缝 — 按顺序逐级排查
Hairline gaps have six ordinary causes and one that appears only in motion; work them top to
bottom, never a negative cell gap or PPU 31.99: atlas Tight Packing off and Padding ≥ 4 → mipmaps
off on tileset and atlas → AA and MSAA off → → even pixel dimensions →
equal to the tile's width → gaps only while the camera moves: . The
ladder with each failure: §5. Rows 1 and 2 are ;
authoring the tilemap is .
UncompressedassetsPPUgridSnapping = PixelSnappingreference/sharpness.mdunity-sprite-atlasunity-tilemap发丝般的缝隙有六个常见原因,以及一个仅在运动时出现的原因;请从上到下逐项排查,
绝不要使用负的 cell gap 或 31.99 的 PPU:关闭 atlas 的 Tight Packing 并将 Padding 设为 ≥ 4 →
关闭 tileset 和 atlas 的 mipmaps → 关闭 AA 和 MSAA → 使用 →
使用偶数像素尺寸 → 使 等于 Tile 的宽度 → 仅在相机移动时出现缝隙:
。包含每种失败情况的排查阶梯:
§5。第 1、2 行对应 ;
Tilemap 制作属于 。
UncompressedassetsPPUgridSnapping = PixelSnappingreference/sharpness.mdunity-sprite-atlasunity-tilemap6. Cinemachine writes orthographic size too
6. Cinemachine 也会写入 orthographic size
The pixel camera owns orthographic size, and Cinemachine writes it every frame too: jitter, plus
framing that pops between shots. Put the extension on every camera
rig, through its Add Extension dropdown. Follow, dead zones, confiners, blends and the component
names for each Cinemachine major: → .
CinemachinePixelPerfectunity-camerareference/pixel-perfect-follow.md像素相机负责管理 orthographic size,而 Cinemachine 也会每帧写入该值,造成抖动,
并在镜头切换时引发构图跳变。请通过 Add Extension 下拉菜单,为每个相机 rig 添加
extension。关于 Follow、dead zone、confiner、blend,
以及各个主要版本 Cinemachine 的组件名称: →
。
CinemachinePixelPerfectunity-camerareference/pixel-perfect-follow.md7. UpscaleRenderTexture
versus UI text and post-processing
UpscaleRenderTexture7. UpscaleRenderTexture
与 UI 文本及后处理
UpscaleRenderTextureOne cause, two symptoms: the scene is rendered small and then scaled up, and anything that runs
after that scale-up — or gets caught inside it — is working at the wrong resolution.
Post-processing then filters an enlarged image: leave , or inject a
2D renderer feature after post-processing, since a plain on a URP 2D
renderer is ignored without an error. UI text on a Screen Space – Camera canvas softens with
the scene: set the canvas to Screen Space – Overlay, the route that holds. The ranked
alternatives and where canvas and font work goes: §2. Confirm
either fix in a windowed run with the canvas and a volume in the scene — a headless check shows
neither symptom.
gridSnapping = PixelSnappingScriptableRendererFeaturereference/motion-and-upscale.md一个原因会产生两种症状:场景先以较小尺寸渲染再放大,而任何在放大之后运行的内容,
或被包含在放大过程中的内容,都会使用错误的分辨率工作。
后处理随后会过滤放大后的图像:请保持 ,
或者在后处理之后注入 2D renderer feature,因为普通的
添加到 URP 2D renderer 上时会被静默忽略,不会报错。
使用 Screen Space – Camera Canvas 的 UI 文本也会随场景一起变软:
请将 Canvas 设置为 Screen Space – Overlay,这是能够保持清晰的方案。
按优先级排列的备选方案,以及 Canvas 和字体相关工作的归属:
§2。请在窗口模式下运行场景,并同时放入 Canvas 和 Volume,
以确认任一修复是否生效;headless 检查无法显示这两种症状。
gridSnapping = PixelSnappingScriptableRendererFeaturereference/motion-and-upscale.md8. Micro-stutter is physics, not rendering
8. 微小卡顿来自物理系统,而不是渲染
A sprite driven by stutters while everything else is smooth: physics advances on a
fixed timestep and rendering does not, and snapping makes the sub-pixel error visible. The fix is
on every physics-driven sprite;
a matched fixed timestep and camera follow in tighten it —
§3. Confirm it in play mode with a moving rigidbody. The
movement code itself is .
Rigidbody2DRigidbody2D.interpolation = RigidbodyInterpolation2D.InterpolateLateUpdatereference/motion-and-upscale.mdunity-2d-controller由 驱动的 Sprite 会卡顿,而其他内容都很流畅:物理系统按固定时间步推进,
渲染却不是如此,而吸附会放大并显现亚像素误差。修复方式是在每个由物理驱动的 Sprite 上设置
;
匹配的 fixed timestep 设置以及在 中执行相机跟随,可进一步收紧抖动 —
§3。请在 play mode 下使用移动中的 rigidbody 进行确认。
移动代码本身属于 。
Rigidbody2DRigidbody2D.interpolation = RigidbodyInterpolation2D.InterpolateLateUpdatereference/motion-and-upscale.mdunity-2d-controller9. Migration
9. 迁移
Wrong component for the pipeline — URP in force, on the
camera: remove the package and the component, add the URP one, re-enter the settings (booleans do
not migrate into enums). finds it. Deprecated booleans on
the right component still compile, as a warning, not an error — so bool-style code compiling
proves nothing about which component you are on. Read the type, not the property names.
UnityEngine.U2D.PixelPerfectCameraPipelineDetection.HasWrongComponentOld URP namespace (), no 2D renderer under
URP, and HDRP, which has no Pixel Perfect Camera at all: steps for all five cases, and the
bool → enum mapping, via §3.
UnityEngine.Experimental.Rendering.Universalreference/pipeline-and-migration.md管线对应错误 — 当前生效的是 URP,但相机上使用了
:移除该包和组件,添加 URP 版本,并重新填写设置
(布尔值不会自动迁移到枚举)。 可检测此问题。
正确组件上的已弃用布尔值仍可编译,但只会产生警告,而不是错误——
因此,bool 风格代码能够编译并不能证明当前使用的是哪个组件。请读取类型,而不是属性名称。
UnityEngine.U2D.PixelPerfectCameraPipelineDetection.HasWrongComponent旧 URP namespace()、
URP 下没有 2D renderer,以及完全没有 Pixel Perfect Camera 的 HDRP:
这五种情况各自的处理步骤,以及 bool → enum 映射,参阅
§3。
UnityEngine.Experimental.Rendering.Universalreference/pipeline-and-migration.mdScope — what this skill does NOT do
范围 — 此 skill 不负责的内容
Slicing sheets, pivots, rects, 9-slice borders and outlines are — this skill
only says which pivot values keep a sprite on the grid. Atlas packing, padding, packer mode and
atlas memory are , which rows 1 and 2 of §5 hand off to. Tilemaps, palettes
and rule tiles are ; §5 ends at "the seam is not the tilemap's fault". Parallax
and sorting are .
unity-2d-spritesunity-sprite-atlasunity-tilemapunity-2d-renderingResolving the active render pipeline, URP asset and renderer configuration, Volumes and Render
Graph passes are — §1 reads the pipeline, it does not set it. The canvas itself
— render mode, scaler, layout — is , and font assets and CJK glyph coverage are
; §7 only says which canvas mode escapes the upscale. Before/after screenshots and
connecting to a live Editor at all are .
unity-render-urpunity-ui-uguiunity-game-uiunity-debugArt direction is out of scope in both directions: this skill will not tell you a resolution is
too low for your art, and it does not apply to high-resolution or hand-painted 2D, where point
filtering and snapping make smooth art look wrong.
Sprite sheet 切片、pivot、rect、9-slice 边框和 outline 属于 —
此 skill 只说明哪些 pivot 值能让 Sprite 保持在网格上。
Atlas 打包、Padding、packer mode 和 atlas 内存属于 ,
§5 的第 1、2 行会将其转交出去。Tilemap、调色板和规则 Tile 属于 ;
§5 的范围止于“接缝并非 Tilemap 本身的问题”。视差和排序属于 。
unity-2d-spritesunity-sprite-atlasunity-tilemapunity-2d-rendering解析当前生效的渲染管线、URP asset 和 renderer 配置、Volume 以及 Render Graph pass,
属于 — §1 只读取管线,不负责设置它。
Canvas 本身 — render mode、scaler、layout — 属于 ;
font asset 和 CJK 字形覆盖属于 ;§7 只说明哪种 Canvas 模式能够避开放大问题。
前后对比截图以及任何连接到实时 Editor 的操作都属于 。
unity-render-urpunity-ui-uguiunity-game-uiunity-debug美术方向不在此 skill 的范围内:它不会判断某个分辨率是否低于美术资源所需的分辨率,
也不适用于高分辨率或手绘 2D 内容,因为 Point 过滤和吸附会让平滑画面看起来不正确。
Reference
参考资料
- — both components member by member, enums with old-bool equivalents, combinations,
reference/api-and-enums.md.pixelSnapSpacing - — the import settings table, reference resolutions, the tilemap seam ladder.
reference/sharpness.md - — pipeline reads, assembly names, migration steps.
reference/pipeline-and-migration.md - — the Cinemachine rule, the upscale's side effects, physics stutter.
reference/motion-and-upscale.md - Code: (resolve the pipeline, pick the type, detect a mismatch),
PipelineDetection.cs(enum-style),CameraSetupURP.cs(bool-style, standalone package),CameraSetupBuiltIn.cs(the four import settings from §2).SpriteImportFix.cs
- — 逐成员介绍两个组件、 枚举及其旧布尔值对应项、推荐组合和
reference/api-and-enums.md。pixelSnapSpacing - — 导入设置表、参考 分辨率和 Tilemap 接缝排查阶梯。
reference/sharpness.md - — 管线读取方式、 程序集名称和迁移步骤。
reference/pipeline-and-migration.md - — Cinemachine 规则、 放大操作的副作用和物理卡顿。
reference/motion-and-upscale.md - 代码:(解析管线、选择 类型并检测不匹配)、
PipelineDetection.cs(枚举风格)、CameraSetupURP.cs(布尔值风格、独立包)、CameraSetupBuiltIn.cs(§2 中的四项导入设置)。SpriteImportFix.cs