このリポジトリは、Unityプロジェクトで null参照によるエラーを未然に防ぐための、シンプルで強力なエディタ拡張ツールです。[NotNull] 属性を付けるだけで、インスペクター上で必須のフィールドが空になるのを防ぎ、開発効率を向上させます。
[NotNull]属性:SerializeFieldを持つフィールドに付けることで、インスペクター上でnull値を許容しないようにします。- NotNull検証ウィンドウ: プロジェクト内の全シーンを対象に、
[NotNull]属性が付いているにもかかわらず値が設定されていないフィールドを一括で検索し、一覧表示します。 - プレイモード突入防止: 検証でエラーが一つでも見つかった場合、プレイモードへの移行を自動的にブロックし、致命的なランタイムエラーを防ぎます。
-
コードのインポート:
- このリポジトリのスクリプトをUnityプロジェクトの
Assetsフォルダにインポートします。
- このリポジトリのスクリプトをUnityプロジェクトの
-
[NotNull]属性の適用:- nullを許容したくないフィールドの上に
[NotNull]属性を追加します。using UnityEngine; using JinStudio.NotNull; public class MyPlayer : MonoBehaviour { [NotNull] public Transform playerSpawnPoint; [SerializeField] [NotNull] private Rigidbody playerRigidbody; }
- nullを許容したくないフィールドの上に
-
NotNull検証ウィンドウの使用:
[NotNull]属性は、UnityEngine.Objectを継承する型(GameObject,Transform,Componentなど)のフィールドに対してのみ有効です。- このツールは開発時のエディタ専用機能であり、ビルドされたゲームのパフォーマンスには一切影響を与えません。
このプロジェクトはMITライセンスの下で公開されています。詳細は LICENSE ファイルをご覧ください。
This repository provides a simple yet powerful editor extension tool for Unity designed to prevent errors caused by null references. By simply using the [NotNull] attribute, you can enforce required fields in the inspector and improve your development workflow.
[NotNull]Attribute: Apply toSerializeFieldfields to disallow null values in the inspector.- NotNull Validation Window: Scans your entire project for fields that have the
[NotNull]attribute but are unassigned, listing them all in one place. - Play Mode Prevention: Automatically blocks you from entering Play Mode if any validation errors are found, preventing critical runtime errors.
-
Importing the Code:
- Import the scripts from this repository into the
Assetsfolder of your Unity project.
- Import the scripts from this repository into the
-
Applying the
[NotNull]Attribute:- Add the
[NotNull]attribute above any field you don't want to be null.using UnityEngine; using JinStudio.NotNull; public class MyPlayer : MonoBehaviour { [NotNull] public Transform playerSpawnPoint; [SerializeField] [NotNull] private Rigidbody playerRigidbody; }
- Add the
-
Using the NotNull Validation Window:
- Open the validation window from the Unity editor menu:
Tools > JinStudio > NotNull Attribute Setting. - You can configure the Validation Scope, Language, and enable/disable the Play Mode Blocker.
- Click the
Run Validationbutton to perform a manual check at any time. - Click the
Go Tobutton in the error list to highlight the corresponding GameObject in the Hierarchy.
- Open the validation window from the Unity editor menu:
- The
[NotNull]attribute is only effective for fields of types that inherit fromUnityEngine.Object(e.g.,GameObject,Transform,Component). - This tool is an editor-only utility for development support and has zero impact on your built game's performance.
This project is licensed under the MIT License. See the LICENSE file for more details.
이 리포지토리는 유니티 프로젝트에서 null 참조로 인한 오류를 미연에 방지하기 위한, 간단하고 강력한 에디터 확장 도구입니다. [NotNull] 속성을 붙이는 것만으로 인스펙터에서 필수 필드가 비어있는 것을 막고 개발 효율을 향상시킬 수 있습니다.
[NotNull]속성:SerializeField를 가진 필드에 적용하여, 인스펙터에서 null 값을 허용하지 않도록 합니다.- NotNull 검증 창: 프로젝트 내 모든 씬을 대상으로,
[NotNull]속성이 붙어있지만 값이 할당되지 않은 필드를 일괄적으로 검색하고 목록으로 보여줍니다. - 플레이 모드 진입 방지: 검증 시 오류가 하나라도 발견되면 플레이 모드 진입을 자동으로 차단하여, 치명적인 런타임 에러를 예방합니다.
-
코드 임포트:
- 이 리포지토리의 스크립트들을 유니티 프로젝트의
Assets폴더로 임포트합니다.
- 이 리포지토리의 스크립트들을 유니티 프로젝트의
-
[NotNull]속성 적용:- null을 허용하고 싶지 않은 필드 위에
[NotNull]속성을 추가합니다.using UnityEngine; using JinStudio.NotNull; public class MyPlayer : MonoBehaviour { [NotNull] public Transform playerSpawnPoint; [SerializeField] [NotNull] private Rigidbody playerRigidbody; }
- null을 허용하고 싶지 않은 필드 위에
-
NotNull 검증 창 사용:
[NotNull]속성은UnityEngine.Object를 상속하는 타입(GameObject,Transform,Component등)의 필드에 대해서만 유효합니다.- 이 도구는 개발을 보조하는 에디터 전용 기능으로, 빌드된 게임의 성능에 전혀 영향을 주지 않습니다.
이 프로젝트는 MIT 라이선스 하에 공개되어 있습니다. 자세한 내용은 LICENSE 파일을 참조하십시오.