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.
What is the code of your SimplifiedSpriteAnimator
.
Can you add a Debug.Log(ImageComponent == null, gameObject);
(2nd argument is important) and click on the message where it's printed true
? That way, you will see which gameObject has not been set up properly.
Answer by lvskiprof · Sep 29, 2020 at 11:30 PM
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.
Your answer
Follow this Question
Related Questions
Better way to mask an image with children 0 Answers
is there simple way to put random sprite to gameobject multi child with no repating. 1 Answer
Prefab UI Slider misses the fill and background items... 0 Answers
Zoom and pan an image 0 Answers
Can't add scripts - "Can't add script behaviour TMP_CoroutineTween [...]". 5 Answers