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.