Hide "readonly" fields from the Inspector

A readonly field decorated with the [SerializeField] attribute causes Unity to display it in the Inspector. However, changes to the field through the Inspector have no effect. This came up in this thread .

In order to avoid future confusion, even though the behaviour is documented here, I suggest:

  1. Emit a compile error if the [SerializeField] attribute is used on a readonly or const field. Not sure if this is possible though, perhaps through Visual Studio Tools for Unity?

  2. Do not display readonly field in the Inspector or display it as disabled element, so it’s clear you can’t change it.

2 Likes

As I posted in the other thread I was unable to recreate this issue myself. If you could share an example script or file a bug report it would be appreciated :slight_smile:

Crossing fingers that @MrLucid72 is able to provide a script to reproduce the issue :slight_smile: