Communitygithub.com

unity-technologies/2d-pixel-perfect

Unityプロジェクトでピクセルパーフェクトな2Dレンダリングを設定、診断、修正します。レトロ風やピクセルアートの2Dゲームに使用します。

2d-pixel-perfect とは?

このスキルは、Unityプロジェクトでピクセルパーフェクトな2Dレンダリングを実現するための包括的なガイドとツールを提供します。URP(Universal Render Pipeline)とBuilt-inレンダーパイプラインの2つの完全に異なる実装に対応しており、パイプラインの自動検出から適切なコンポーネントの選択までをサポートします。主な診断項目には、スプライトのインポート設定(フィルターモードをPointに設定、ミップマップ無効化、圧縮なし)、カメラ設定(直交投影、ピクセルパーフェクトカメラコンポーネント、HDR/MSAA無効化)、エディタースナップ設定、プロジェクト品質設定(アンチエイリアシング無効)が含まれます。また、ぼやけたスプライト、タイルマップの隙間、Cinemachineとの競合、アップスケール時のUIテキストぼやけなど、一般的な問題とその解決策も提供します。このスキルはClaude Code、Cursor、CodexなどのAIエージェントと連携して使用でき、Unityプロジェクトのピクセルパーフェクト設定を自動化・最適化します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/unity-technologies/skills/tree/main/skills/2d-pixel-perfect

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Unityプロジェクトでピクセルパーフェクトな2Dレンダリングを設定、診断、修正します。


⚠️ 完全に別々の2つの実装があります

Unityのピクセルパーフェクトレンダリングは1つのシステムではありません。レンダーパイプラインごとに、互換性のない2つの独立した実装があります。コードを記述または診断する前に、必ずパイプラインを検出してください。

URPBuilt-in
コンポーネントUnityEngine.Rendering.Universal.PixelPerfectCameraUnityEngine.U2D.PixelPerfectCamera
パッケージURPに組み込み — 追加インストール不要com.unity.2d.pixel-perfect v6.0.0以上
APIスタイル列挙型(gridSnapping、cropFrame)ブール値(pixelSnapping、upscaleRT、cropFrameX/Y)

URPプロジェクトには com.unity.2d.pixel-perfect をインストールしないでください。

→ 常に最初に DetectPipeline() を呼び出し(references/pipeline-detection.cs)、その結果に基づいてセットアップ、診断、修正を分岐させてください。


このスキルを使用すべきでない場合

  • HD 2Dや高解像度2Dゲーム — ピクセルスナップとポイントフィルタリングにより、滑らかなアートが不自然に見えます
  • UIのみのシーン — 代わりにCanvas Scalerを使用してください
  • HDRPプロジェクト — Pixel Perfect Cameraはサポートされていません

重要な注意点

⚠️ 最初にレンダーパイプラインを検出してください — URPとBuilt-inでは異なるPixel Perfect Cameraコンポーネントが使用され、互換性がありません。 ⚠️ フィルターモード = Pointが最も重要な修正です — バイリニアフィルタリングはUnityのデフォルトであり、スプライトがぼやける原因のほとんどです。 ⚠️ アンチエイリアシングは無効にする必要があります — 品質設定とカメラの両方で。AAはピクセルのエッジを積極的にぼかします。

主要な原則

1. パイプライン検出とカメラコンポーネントの選択

このファイル上部の2パス比較表を参照してください。アセンブリ名の注意点:スタンドアロンのBuilt-inパッケージは Runtime/ フォルダにインストールされますが、asmdefの "name" フィールドは Unity.2D.PixelPerfect であり、Runtime サフィックスは付きません。HDRPはサポートされていません — 「よくある問題」セクションのHDRPフォールバックセクションを参照してください。

→ コード:references/pipeline-detection.cs — DetectPipeline()、GetPixelPerfectCameraType()、および移行時の不一致チェック。

2. 診断優先のアプローチ

変更を行う前に必ず診断してください。調査結果を報告し、壊れているものだけを修正してください。

3. 適切なスコープで作業する

デフォルトはシーンスコープです。ユーザーが明示的に要求した場合にのみ、プロジェクト全体をスキャンしてください。


診断チェックリスト

スプライトインポート設定:

  • フィルターモード = Point (no filter) — 対象範囲のすべてのスプライトで
  • ミップマップ = 無効
  • 圧縮 = None / 無圧縮
  • PPUがシーン内のすべてのスプライトで一貫している
  • スプライトピボットがカスタム/ピクセルモードに設定されている — 奇数サイズのスプライト(例:15×15)の中央ピボットは7.5pxに位置し、0.5pxの位置ずれが発生します

→ コード:references/sprite-settings.cs — GetImporter() および FixSpriteImportSettings()。

エディタースナップ設定:

  • グリッドサイズ = すべての軸で 1 / assetsPPU(例:PPU 16 → 0.0625、PPU 100 → 0.01)
  • グリッドスナップがグリッドおよびスナップオーバーレイで有効
  • 既存のGameObjectをスナップするには:選択 → Align Selected → All Axes

カメラ設定:

  • カメラ投影 = 直交
  • Pixel Perfect Cameraコンポーネントが存在し、パイプラインに適したタイプである
  • allowHDR、allowMSAA、allowDynamicResolution がすべて false
  • シーンビューにカメラギズモに2つの緑色のバウンディングボックスが表示される — 実線 = 表示領域、点線 = 基準解像度

→ コード:references/camera-setup-urp.cs — URPカメラ + PP Cameraの完全な設定。 → コード:references/camera-setup-builtin.cs — Built-inスタンドアロン設定。

プロジェクト品質設定:

  • アンチエイリアシング = 品質設定で0
  • 異方性フィルタリング = 無効

APIリファレンス

完全なプロパティ/メソッドテーブル、GridSnapping および CropFrame 列挙値、推奨設定: → references/api-reference.md — カメラ設定コードを作成またはレビューする際に参照してください。

列挙型の簡単な概要:

GridSnapping:None · PixelSnapping(標準) · UpscaleRenderTexture(本物の低解像度感;ポストプロセッシングやUIテキストとは互換性がありません)

CropFrame:None · Pillarbox · Letterbox · Windowbox(最も安全なデフォルト) · StretchFill


基準解像度

アセット作成前に選択してください。アセット制作開始後は変更しないでください。

基準解像度1080p1440p4K
320 × 1806×8×12×
480 × 2704×~5.3×8×
640 × 3603×4×6×

320×180が最も安全な一般的な選択肢です。整数倍が合わない画面(例:1366×768)の場合は、cropFrame = Windowbox を使用して黒いバーを追加し、小数倍にストレッチするのを避けてください。


移行と互換性

Built-inスタンドアロンコンポーネントを使用したURPプロジェクト

症状:DetectPipeline() がURPを返すが、カメラに UnityEngine.U2D.PixelPerfectCamera がある。スタンドアロンコンポーネントに ENABLE_URP 条件付きコードがあるため、症状は微妙です。

修正:

  1. パッケージマネージャーから com.unity.2d.pixel-perfect を削除
  2. 各カメラから UnityEngine.U2D.PixelPerfectCamera を削除
  3. UnityEngine.Rendering.Universal.PixelPerfectCamera を追加
  4. 再設定 — ブール値(pixelSnapping、upscaleRT、cropFrameX/Y)が列挙型(gridSnapping、cropFrame)になります

→ 検出コード:references/pipeline-detection.cs(ファイル下部)。

古いURP名前空間(Unity 2022未満 / URP 13.x未満)

症状:UnityEngine.Experimental.Rendering.Universal を参照するコンパイラエラー。

修正:using UnityEngine.Experimental.Rendering.Universal; を using UnityEngine.Rendering.Universal; に置き換えてください。アセンブリ修飾されたタイプ文字列を更新してください。[MovedFrom] 属性が自動的にシリアル化を処理します — GameObject上のコンポーネントはアップグレード後も維持されます。


よくある問題と解決策

ぼやけたスプライト

修正:対象範囲のすべてのスプライトでフィルターモードをPointに設定し、ミップマップを無効にし、品質設定でAAを無効にします。 → コード:references/sprite-settings.cs

タイルマップのタイル間の隙間

順番に確認してください — 負のセルギャップやPPU = 31.99のような回避策は、カメラが移動すると壊れます。

#チェック項目修正方法
1スプライトアトラスでTight Packingがオフ、Padding ≥ 4、Sprite Packer Modeが有効?エディター設定でSprite Packer Modeを有効にする;アトラスでPadding ≥ 4に設定し、Tight Packingをオフにする
2タイルセットテクスチャとアトラスでミップマップが無効?Generate Mip Mapsを無効にする
3AA = 0、カメラでMSAAがオフ?AAをグローバルに無効にする
4圧縮 = None?RGBA 32ビット無圧縮
5すべてのタイルスプライトのピクセル寸法が偶数?奇数の寸法は0.5pxのグリッドオフセットを引き起こします
6PPU = タイルのピクセル幅?(16×16 → PPU 16)PPUの不一致は物理的な隙間を残します
7上記すべてを通過後、カメラ移動時のみ隙間が発生?PP Cameraのピクセルスナップを使用;cellGap = -0.01f は使用しないでください

Cinemachineとの競合

原因:CinemachineとPixel Perfect Cameraの両方が毎フレーム直交サイズに書き込みます。

修正:各Virtual CameraのAdd Extensionドロップダウンから CinemachinePixelPerfect 拡張を追加してください。コード内で AddComponent を使用して追加しないでください。

既知の制限事項:

  • 仮想カメラ間のカメラブレンドは、遷移中はピクセルパーフェクトではありません
  • UpscaleRenderTexture は有効なピクセルパーフェクト直交サイズを減らし、フレーミングがずれる可能性があります
  • Target Group + Framing Transposerは目に見えるカクつきを引き起こします(修正不可)

upscaleRT 使用時のポストプロセッシングのぼやけ

原因:ポストプロセッシングはPP Cameraがレンダーテクスチャをアップスケールした後に実行されます。

簡単な修正:upscaleRT を無効にします。ポストプロセッシングはネイティブ画面解像度で実行されます。

高度な修正(Unity 6 URP):RenderPassEvent2D.AfterRenderingPostProcessing で ScriptableRendererFeature2D を注入します。2D固有の基本クラスを使用してください — ScriptableRendererFeature(3D基本クラス)はURP 2Dレンダラーでは静かに無視されます。

upscaleRT 使用時のUIテキストのぼやけ

ステータス:既知のUn

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

unity-technologies/audio-setup-mixers

Scans the scene and audio assets to appropriately route Audio Sources into existing Audio Mixer Groups, classifying each source by what it plays. Use when the user asks about cleaning up mixer assignments, routing audio through a mixer, or which group a sound belongs in. Creating mixers and groups, and setting volumes, are not automated — the skill inventories what exists and asks the user to add anything missing.

unity-technologies/build-live-game

Build and operate a live game using Unity Services. Use when the user needs to implement, connect, or debug backend-driven features — battle passes, achievements, player progression, cloud saves, leaderboards, matchmaking, virtual economies, server-authoritative logic, anti-cheat, player accounts and authentication, remote configuration, feature flags, A/B testing, analytics, or cloud resource deployment. Triggers on live-ops, live service, backend, server authority, cloud code, cloud save, remote config, player data, retention, monetization loop, season pass, ranking, multiplayer sessions, lobbies, or any Unity Services integration.

unity-technologies/generate-editor-search-query

Generates Unity Search / Quick Search queries and opens the Unity Search window for read-only Unity Editor asset or scene-object lookup requests. Always use when the user asks to find, search, show, locate, filter, look up, query, or list concrete assets or scene objects in the current project or scene, even if Unity Search is not named. Covers materials, textures, prefabs, scenes, scripts, shaders, GameObjects, components, Lights, Cameras, UI objects, labels, paths, references, selected or named assets, and asset types. Also use when the user explicitly mentions Unity Search, Quick Search, Search window, open Search, or asks what Unity Search query to use. Do not use for general project overview, project structure, folder-purpose summaries, gameplay/system explanations, how-to programming questions, web search, repository text search, build logs, package installation, menu or settings search, modifying results, or non-Unity filesystem search unless the user explicitly asks to use Unity Search.

unity-technologies/implement-in-app-purchases

Implement, configure, and debug Unity In-App Purchases (IAP) — store connection, product catalog, consumable/non-consumable/subscription purchases, two-step pending-confirm flow, receipt validation, entitlement checking, restore transactions, Apple extensions (promotional purchases, Ask-to-Buy, code redemption), and Google Play extensions (subscription upgrade/downgrade), D2C Capabilities(direct to customer), 3rd party payment provider (Stripe/Coda) via Unity IAP/Unity Cloud. Use when the user needs to add, modify, debug, or migrate from native Android/iOS billing, 3rd party packages(RevenueCat/Adapty/Essential Kit/Unipay supported) to IAP. Triggers on microtransactions (MTX), monetization, real-money purchases, store purchases, buying items, support D2C, purchase via Stripe/Coda, migrate from native billing(Google's BillingClient or Apple's StoreKit/SKPaymentQueue/SKProduct)/RevenueCat/Adapty/EssentialKit/Unipay.

unity-technologies/initialize-ai-navigation

Sets up and configures the Unity AI Navigation system — NavMesh surfaces, NavMesh agents, obstacles, links, modifiers, areas and costs. Use when creating walkable navigation meshes, adding pathfinding agents, setting up patrol routes, configuring obstacle avoidance and carving, connecting separate NavMeshes with links, coupling navigation with animation, or troubleshooting navigation issues.

unity-technologies/levelplay-unity-integration

Integrates the LevelPlay Mediation SDK via the Ads Mediation UPM package. Use when a developer asks about adding ads to a Unity game, implementing rewarded, interstitial, or banner ads, setting up ad mediation, configuring ad networks, installing or updating the Ads Mediation package, troubleshooting LevelPlay namespace errors, resolving Android gradle or iOS CocoaPods dependency issues for ads, configuring ATT or privacy settings for ad compliance, tracking impression-level revenue (ILRD), initializing the LevelPlay SDK, or setting up ad unit IDs. Also use when a developer wants to monetize their Unity game with ads, asks how to get started with LevelPlay, ads, or mediation, or needs help with any part of the LevelPlay integration workflow including platform-specific setup for iOS or Android. Also use when upgrading the LevelPlay or IronSource SDK version, migrating from deprecated IronSource.Agent APIs, or migrating a game from Unity Ads to LevelPlay.

unity-technologies/localization

Sets up and configures Unity Localization, including locales, String/Asset Tables, CJK font support, and Addressables workflows. Use when the user wants to add languages to a project, translate UI text, support Asian (CJK) languages with TMP fonts, or mentions i18n, l10n, multilingual support, or making a game support multiple languages.

unity-technologies/manage-sprite-atlas

Manage SpriteAtlas using prebuild pipeline with IPreprocessBuildWithReport (DEFAULT approach). Use it to configure master atlases, variant atlases, texture settings, packing settings, and platform-specific configurations. Use when the user asks about creating sprite atlases, optimizing sprites, configuring atlas settings, adding sprites to atlases, creating variant atlases, implementing automated atlas generation, or runtime sprite atlas access. Always use prebuild approach unless user explicitly requests manual authoring.

unity-technologies/migrate-birp-to-urp

Plans, executes, and troubleshoots Unity projects moving from the Built-in Render Pipeline (BiRP/BIRP/Built-in RP) to the Universal Render Pipeline (URP). Use when the user asks to upgrade, convert, switch, or migrate a project, scene, material, or shader to URP/Universal Render Pipeline; fix pink or magenta materials after URP; convert Built-in materials/shaders; move a 2D project to URP 2D; review lighting, quality, post-processing, baked lightmaps, or reflection probes after URP; or diagnose visual problems after a render-pipeline migration.

関連スキル