- Home /
Other
Unity UI not rendering ammo icon when build unity 2018.4.18
I have an ammo counter setup in my scene that shows the fill ratio for each weapon and cycles through the different UI icons when player changes weapons, and it works fine in the editor but when i built my project only the UI icon for the primary weapon is visible but when the player changes weapons the icon disappears.
Primary Weapon with visible UI icon on the bottom left corner:
Secondary Weapon with missing UI on the bottom left corner:
Answer by BBIT-SOLUTIONS · Mar 08, 2020 at 10:15 PM
When it works in editor, then it's maybe a problem with the screen resolution.
Think you can test, if the problem already appears when you change the screen dimensions in the game-view.
And then you should maybe check if both images (in the assets) have same dimensions (pixel-size, aspect-ratio, filetype) and same import settings.
Also maybe check if you are anchoring your images in the UI or if you have set any hard-coded pixel-values (for left, right, top or bottom). That could also maybe make the image disappear in worst-case for some screen-resolutions.
Do you also just exchange the sprite of the same image component or do you use extra GameObjects for each icon? In second case, also ensure, that RectTransform of all GameObjects has same settings.
Thank you for your feedback. I tried messing around with screen resolution but it works absolutely fine in the game view, and the sprites have same import settings and same size, resolution etc. Tried changing the anchoring and transform and still works in game view but does not work when build. And i have a prefab called "ammocounter" that deals with switching the weapon icons based on which weapons are chosen. Each weapon prefab have their own set of icon images attached to them that get called by the ammocounter prefab. The ammocounter prefab also has an opacity slider that basically hides the weapon icon for the unselected weapon and shows the icon for selected weapon that basically takes care of switching the icons. Still don't understand why it would not show in the build but work fine in the editor.
Ok, i see. Happens the problem only with exactly this secondary weapon or with other weapons, too? And because you are using opacity for hiding them: Do you have ensured, that all variables which are responsible for that, are defined (e.g. in Awake() or Start()). If they are undefined, it could maybe happen, that it's randomly set to true (or 1) in editor and false (or -1 etc) in your build...
Here's the code i am using, not using any awake or start function but i have an initialize and the default unselectedOpacity has a value of .5 which is edited to be 0 in the prefab in the editor. And the problem happens only with the secondary weapons but not with the primary weapon.
Follow this Question
Related Questions
Display Ammo Count Above Player 1 Answer
FPS UI ammo display problem 0 Answers
Texture Glitch 0 Answers
Issues with UnityEngine.UI when referenced in a class library, since Unity 2019 1 Answer