Changing prefab of a GameObject at runtime C#

Hello ! I’m new to unity and sorry if this is too simple but i’ve searched for some time without finding a solution, here’s my problem:
So I have a script using GameObject variable where it’s defined the object my UI elements (Arrows etc.) elements will follow in game mode.I’m also using a button which instantiate a different Object and I’d like to assign that to the GameObject instead.Since it’s runtime I cannot drag and drop something that’s not created yet.
Thanks in advance!

If I understand correctly you want to have a reference of your instanciated GameObject in your script ?
You said that you have a button wich instantiate GameObject, so why don’t you add few lines in the button script like :

private GameObject YourRef;
public void ButtonMethod()
     GameObject o = Instantiate(gameObject);
      YourRef = o;

Is that what you need ? Have a good day :slight_smile: