The type 'UnityEngine.Vector3' cannot be declared const

Hello! It's been a while since I last programmed in C#, and I've run into this error when compiling one of my scripts:

The type 'UnityEngine.Vector3' cannot be declared const

Here is the code that is causing it:

public const Vector3 up = new Vector3(0, 0, 1);

I wasn't aware of any C# mechanic that could allow specific types to explicitly prevent the const specification. I can't find anything on that matter either on the forums, Answers, nor Google. Would anyone care to enlighten me? I wish there was an error code database I could look into.



Only the C# built-in types (excluding System.Object) may be declared as const.

You may want to look into readonly instead - very similar, but allows writing at construction time

If you change your field into a property with only a getter, you will get the desired behavior.

public Vector3 up { get { return new Vector3(0, 0, 1); } }