Initialize constant fields in Component at runtime

I’m trying to add a Component to a GameObject at runtime which has constant fields (or more specifically, a property that has a public get and a private set). Normally I would set these values in the constructor but I’m not seeing a way to do this because the only way I know to add a component is by using GameObject.AddComponent which seems to instantiate the Component without any options. So is there any way to achieve this?

I am trying to create a button with a path to specify what location should be accessed when the button is pressed so I have created a simple Component with a string field to store that value. Ideally, this field would be set when the object/component is first created, and then not be allowed to change. Possibly there is another solution other than what I am looking for above.

Been a little while since a question has made me think.

Best I can come up with is a factory, something like this or this. Its kind of ugly, but might be the best way to do it within Unity.

Why use a script, you should be able to use the string as the button content and use it when pressed? or use

if(button pressed){
     access location/thing
}

I might not be understanding your intentions properly though. If i’m wrong could you clarify what you want to achieve?