Image Component is always null even when I assign it myself in the editor

Hello everyone,

My code is simple. I have a script that references an image component and it assigns a sprite to it.

I’m assigning the image component manually in the editor as you can see in the screenshot here:

For some reason, every time I check for image component. The code tells me it’s null. I added an if(ImageComponent == null) condition to check and it always returns true.

Also, because I assigned this in the editor. I can clearly see if it was accidentally removed for some reason during runtime. But that never happened, I can still see the image component assigned correctly in the editor at all times.

Is that a known bug in Unity 2019.3?

Update: It’s also worth noting that I previously used a sprite renderer component instead of Image component and that worked no problem. But right now I want to use image component since I want to utilize the canvas scaling and anchoring system that Image component uses. I’m starting to think this is an issue with image component specifically.

While I don’t think this will solve your problem, it is best to develop on the Long Term Support version LTS, which is the .4 version. That is the one that will get bug fixes and remain the most stable. You will see periodic updates come out for it, but I am still on 2019.4.1f1, since I have not see the need to include any bug fixes from those later releases (yet). Any version less than .4 is to try out new features that want to introduce and you can run into bugs or it might change how your code interacts with some elements.