and you can use also this kind of variable declaration, similar to setting values to an array:
fixed4 col = { mainColor.r,mainColor.g,mainColor.b,mainColor.a };
I suggest you open the Microsoft HLSL reference. It’s a dry but good source for exact information. Helps a lot when you run into this kind of things especially when starting with shaders.
This is orthogonal to what the OP asked, but avoid using custom names for things unless you have a specific reason. For example using _MainColor instead of the more standard _Color might cause problems, since there are things in Unity that rely on things being named a certain way.
Specifically material.color = myColor; expects the shader to be using _Color, as it’s just an alias for material.SetColor("_Color", myColor);. Really, just don’t ever use material.color and it won’t be a problem.
The other place it’s expected is with fallback shadowcaster passes and replacement shaders. This is really only an issue with an alpha tested shader, where it’s expecting the alpha of the _MainTex is multiplied by _Color.a before doing the clip(). If you’re not using alpha testing, or not using a fallback for the shadowcaster and not using the _CameraDepthNormalsTexture, this can also be safely ignored.
Also lightmapping expects certain things to be named in certain ways, although if you are writing completely custom Lightmapped shaders, you might as well write a Meta pass too.
@bgolus I thought there might be something going to happen with those values after that specific issue was resolved by the author, so I tried to suggest a fix it with minimal changes. But of course you’re absolutely correct.