Adding script in runtime makes pre-set fields null

Hello all,

I have a script in the Assets folder with all the fields pre-set (those who show up above the script’s text in the Inspector).

When I add this script as a component to a GameObject manually (dragging it to the target game object) the fields stay populated as I specified(both in play and non-play mode) , but when I try to add the component via code, using AddComponent(), all the fields go blank.

Is that expected behaviour? It’d so nice if this was allowed.

There’s already a question with an answer to it: