Assigning Instantiated image to gameobject in script

Hi. I’ve tried a lot and nothing works.

  • Gameobject.Find()
  • Instantiating the Image and assigning
    it to the gameobject
  • Instantiating the Image as a
    Gameobject and assigning it to the
    gameobject.

Nothing works.

I instantiated a Gameobject called UI (in the scene it’s called UI(Clone). One of Its children is a UI image called ImageWhiteDot.
I Wish to assign that specific UI Image to a Gameobject declared in one of my scripts, but using Gameobject.find or findbytag, it Just doesn’t seem to find it. If I look at the script in the inspector window, I want to see “ImageWhiteDot” attached/assigned to my Gameobject.

Any help would be appreciated.
Thanks

I would put a script on the prefab with a field for the image and edit the prefab to attach the image to the script’s property on that prefab. Then you can use GetComponentInChildren<>() on your instantiated prefab to get the configured instance of your behavior.

Once you have a reference to your custom behavior, you can just read the image off the field that stores it and do whatever you want with it.

@MaxGuernseyIII Thanks. I’ve just found the solution. For anyone having this issue in the future:

  1. Create Gameobject
  2. Drag everything that you want to instantiate (in my case one prefab for multiplayer spawn) into the gameobject.
  3. Everything like the UI elements etc. can be added into scripts’ variables.
  4. Drag the Gameobject you created into the resource folder and use a script to Load that Prefab

GameObject yourgameobject = (GameObject)Instantiate(Resources.Load(“yourgameobject”));