Search Unity

Can't instantiate UI Image prefab

Discussion in 'UGUI & TextMesh Pro' started by qkson, Apr 24, 2019.

  1. qkson

    qkson

    Joined:
    Jan 15, 2018
    Posts:
    77
    Hey, I have this annoying problem that's driving me nuts and I cant find any solution to it. I want to Instantiate an UI Image prefab via script. I have a public Image variable that I set in inspector, and when I try to Instantiate this I get "The object you want to instantiate is null". It's funny, because I can instantiate an UI Button prefab the same way I want to instantiate the image.
    https://imgur.com/a/v38wrdW
    line 70 is working perfectly, while line 71 is throwing that error.
    Any help will be appreciated, thanks
     
  2. qkson

    qkson

    Joined:
    Jan 15, 2018
    Posts:
    77
    If someone else is having this problem for some reason, I worked around it by making the UI Image from scratch; by making an GameObject and adding different components to it via script.