Public variables empty when adding script dynamically

Hi! I have several scripts that display GUI elements; each one has public textures that I have instantiated by dragging images onto them in the script’s inspector.

When drag’n’dropping these scripts onto a GameObject in the editor, the textures keep their value. However, when adding said script through gameObject.AddComponent(), all textures point to None (Texture).

Do I have to instantiate each texture in the script’s Start() method or is there another way?
Thanks

The scripts only have an inspector once they’ve been instantiated on a gameobject, adding the component from scratch does not reference anything you’ve done to the same component on another object.

You can create a prefab, the script stores its variables within the prefab but you must reference other assets, not instances in the scene. You can then copy the script in the prefab.

You can generate everything procedurally, as you have suggested.

You can set everything up in scene view and everything stays the same once you hit play.

Yeah, that’s basically it. Happy coding :slight_smile: