I am working on a card game that works inside of a canvas.
Occasionally (at least once per battle), one of these cards will just stop being visible. I can disable and reenable them and no change happens, they are still not visible.
I’ve checked all of the subcomponents, their color isn’t transparent, they’re all enabled and active, and the card data object that it is assigned still has health > 0. The cards aren’t dead and continue to act, but they are no longer visible.
The really strange part is that in the editor, I can add new components in the hierarchy, and they WILL show up. But if I duplicate an existing component (ctrl+d) it WON’T show up. Even text objects.
The transform is set to fill, but they’re not small or negative, I’ve already checked all that.
At this point I have no idea what there is even left to check, but this is obviously a very serious issue because most people who play card games like to see the cards on the board lol
Any advice or suggestions would be greatly appreciated. Also I would include code, but I use Model-View-Controller data structure and it would be a lot to include since I’m not sure exactly where the problem could be or even if it’s my fault or Unity’s.
Check their scale. Sometimes mis-animating things can leave one of the dimensions zero, such as the Z dimension.
When they’re invisible, right-click on the RectTransform inspector and reset it. Now drag it around until you can see it. That will isolate if it is RectTransform damage, such as by scaling to zero.
Same applies to all parent Transforms. Never animate things to scale zero.
Here’s more scaling reading:
The proper way to set scales:
NEVER set scale (or any part of scale) to zero or negative.
NEVER use Vector2 because that makes the third term (Z) zero.
ALWAYS use Vector3, and make sure that the .z is either 1.0f, or else your non-zero scale.
Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy with either NaN or Infinity.
I owe you what’s remaining of my hair. I don’t know why it happened so inconsistently, but I did recently add a “shrink to nothing” animation, which should be the only place that is even possible. I reduced the end state to .001f and also reset the local scale in the cleanup function.
Thanks again, I’m happy to have that behind me lol