InspectorOnlyFields
Prevents accidental runtime modifications to inspector-assigned fields through Roslyn analyzer warnings. Add the `InspectorOnly` attribute to serialized fields to enforce inspector-only assignment patterns and catch violations during code analysis, improving data integrity and reducing bugs from unintended field mutations in gameplay code.
com.github.miyaji255.inspector-only-fields Unity Compatibility

Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/inspector-only-fields.git?path=InspectorOnlyFields/Packages/InspectorOnlyFields README Markdown
Copy this to your project's README.md
## Installation
Add **InspectorOnlyFields** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/inspector-only-fields.git?path=InspectorOnlyFields%2FPackages%2FInspectorOnlyFields
```
[](https://www.pkglnk.dev/pkg/inspector-only-fields)README
InspectorOnlyFields
English / Japanese
This package provides an analyzer that warns against assigning on C# code to fields that are assigned from within the Unity inspector.
Installation
You can install this package using UPM (Unity Package Manager).
Use Git URL
- Open Package Manager Window
- Click Add(+) on the status bar
- Select Add package from git URL
- Input
https://github.com/miyaji255/InspectorOnlyFields.git?path=InspectorOnlyFields/Packages/InspectorOnlyFields - Click Add
Use OpenUPM
You can install using OpenUPM. The page is here. https://openupm.com/packages/com.github.miyaji255.inspector-only-fields/
Usage
Add the InspectorOnly attribute to fields to which you want to assign values from the inspector. Then, The analyzer will warn you when assigning a value to the fields.
using InspectorOnlyFields;
using UnityEngine;
public class SampleObject : MonoBehaviour
{
// InspOnly001: The assignment to 'GameObject' is prohibited by the InspectorOnly attribute
[InspectorOnly]
public GameObject GameObject = new GameObject();
void Start()
{
// InspOnly: The assignment to 'GameObject' is prohibited by the InspectorOnly attribute
GameObject = new GameObject();
}
}
Translated by DeepL.com
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In