Cancel parent's serialization variables

I have a parent of a script that has some serialized variables.

But I want a specific child script to have constant values for those values and disallow people from serializing them in the inspector.

How can I cancel the parent’s serialized fields within its child(and giving those fields constant values, or at least values within a script that are not serializable)

public const string MyName = "Kurt Dekker";

Nobody’s changing that, or serializing it either.

The normal way of doing this with inheritance would be to expose these data as properties or accessor methods, and have the child class override the parent’s version. Of course the whole “Unity inspector” aspect throws a wrench into things.

My intention was…umm
as example:

we have this class

public Class parent : MonoBehaviour {
[SerializedField] private string someString = “”;
}

and its child

public Class child : parent {
//I want this string, the “someString” to be serialized on the parent but to have a constant value on the child.

it means that if I use your method I have to do
private new const string someString = “Const value here”

On every single variable the parent class has…
My question is whether there is a more efficient way
}

You can lock value in OnBeforeSerialize().
Additionally, you can make a custom editor that will hide the value or make it readonly.

What is the use-case for this? A child is a specialization of its parent, so as a rule of thumb it should have the same properties, or slightly changed, specialized versions of those. Wanting to serialize something on a parent but not a child seems a bit weird to me at first glance, which does not mean there wouldnt be a viable use case for this tho. Still, a child is always also of the same type as its parent, so the same variable is literally that: the same thing. In order to change it you’ll have to overwrite it, or do some other trickery like reading the value and saving it so some non-serialized variable in the child. Then again, you basically implied that you’d have to do that to every variable of the child class, so there may be something wrong with your approach.