- Home /
Unity Rendering Some Images, But Not Others (World Space UI)
I'll try to be as thorough as I can. I'm using Unity 2019.1.1f1 Personal Edition.
I'm making a world-space UI that is intended to represent a control panel for a futuristic craft. It looks like this in its default state:
When the initialize button is clicked, the blur disappears and a routine starts and does the following:
1. Sets all the images to the proper sprite
2. Lerps the default "gray" button to transparent
3. Lerps the yellow button to opaque
4. Swaps the previous behavior
5. Sets the button to the final state (blue OK)
However, it only works for the first image in the list. Here's what happens:
As you can see, the "first" button works properly, but every other one follows behavior of the next. Note: it works in the inspector
Out of curiosity I dragged the image into the layout group and it was completely invisible (this may take a bit to load)
So, why are none of my images rendering? For the sake of better identifying the problem, I've uploaded screenshots of all the relevant parts of my hierarchy here
Answer by Pengawk · Jul 17, 2019 at 09:46 PM
After several hours of banging my head across the wall, I've come upon the solution.
In my code, in order to set the sprite of the image, I was using the following:
avionicsItems[current].warningButton.sprite = regularButton.warningSprite;
As it would turn out, this has changed some in Unity 2019.1. To properly change a sprite at runtime, you should do the following:
avionicsItems[current].warningButton.overrideSprite = regularButton.warningSprite;
Here's a link to Unity's doc on overrideSprite
I hope anyone that comes across this issue finds this useful.
Your answer
Follow this Question
Related Questions
How do I add a "pointer" to my UI menu? 1 Answer
Difficulties with world space canvas interaction 1 Answer
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
[Solved] Buttons become invisible when scaling game view 1 Answer
Getting the overlapping pixels between a UI mask and a UI image 0 Answers