Unity UI List Element not showing unless I change screen size - unity3d

I have a UI Scroll View in Unity showing a list of Toggles that I dynamically populate. My problem is that when I instanciate a new element in this list, it is in the inspector but it is not rendered on the screen ?
This happens also when i manually add a ListElement GameObject to the content element of the list.
What is very weird is that if I move the window so that the screen size changes, it is drawn... Cf. the two screen shots.
On the first screen shot, I added a ListElement prefab, like you can see, it is not drawn but it is there and active.
Then I resized the Editor Window and it magically pops up... This happens also on a build of the game (on Android for example, it is drawn when screen orientation changes but not before...).
I tried to Force canvas redraw, LayoutForceRebuild but it doesn't work. The fact is that i have no idea why this is happening...
Screen shot 1 :
Screen shot 2 : the red arrow shows what I did to make it drawn
Screen shot 3 : with Show mask enabled on the view port
Screen shot 4 : same as 3 but after resize

I met with this problem too and finally solved it, dunno whether it's a same situation.
I find the window or UI Elements repaints only when refered variables are changed. So when it comes to the ListView, it is not called "OnValueChanged" if you add elements to [ListView.itemsSource]. The solution is to new a list and assign to [ListView.itemsSource].

Related

Unity, at higher resolution (2560 x 1440) tester cannot click the navigation elements on the screen even though they are in position

Here is my issue, the way my game works is that you click on the edges of the screen to navigate. This is done through an Overlay Canvas using OnPointerClick. I colored the navigation areas, and scale the canvas according to screen size and the navigation areas appear on their screen as they should. Yet they CANNOT click any of the elements for some reason. They have another monitor that works without issue. They've noted that their larger monitor is AMD. I've also confirmed that the ability to navigate in game has not been hindered. I have never had this issue (or any other testers) on 1920x1080 monitors.
I have completely exhausted what the issue can be, they cannot even navigate on a bare bones tutorial. Any ideas would be GREATLY appreciated.
Here is an image of their screen and the respective clickable navigation areas.
[img]https://i.imgur.com/NVQkA8g.png[/img]
Unity 2019.2.14f1
Put a Image component without sprite, because without that, you will not detect any click. You can set the alpha to 0 after you see that working.
Also check the anchors of the navigation areas.

UI Panels are not positioning themselves according to screen size

My UI elements inside my panels are scaling fine with screen size, but the distance between my different panels is not. I have 3 panels in my scene at different relative position which i set at 1920x1080 reference resolution, and switching between them using animation. But when i change the game view resolution, these panels do not align themselves right. Here are the screenshots:
These are the panels at 1920x1080 which i set.
These are the panels when i set game view resolution to 2340x1080. As you can see, the "settings" panel is still fine but the "more settings" panel does not repositioned correctly.
The same thing happens when i set game resolution to 800x480.
Please help me..
The easiest way you can achieve what you are attempting to do is to use a component called GridLayoutGroup. Add this component to a parent object, child all three of your UI elements to it, and set the column count to 2. I can add an example in a bit, currently building a project.
Edit: Here is a gif example of the above solution.

UI GameObject not visible in scene tab

I am working on a networking game where a roomListItem shows all the available gamerooms online. for every gameroom a button gets instantiated inside the roomListItem and this happens as intended, the problem is that the button that gets instentiated is invisible, i can resize it but still can't see it.
i already tried moving the button at the bottom of the hierarchy but it's still not visible.
The problem is that you are masking all the content, there is an object named Viewport that contains a mask component, this component causes that all UI elements below it will be masked, you can try:
Remove it.
Change the sprite for another one if you like to mask it in some way.
GIF here: https://share.getcloudapp.com/YEu8JPXN

Zooming doesn't work in Unity although FOV changes

I am working on a 2D project and I want to zoom in my map by scrollwheel. I am sure that my code is working (because during the play mode, field of view changes when scrollwheel is rotated) but no change on the screen is observed.
Besides, during play mode even if I change the field of view manually (from the editor), the screen view remains same. That is, although field of view is observed to be seen changing but the screen view is not.
What are the possible reasons for that?
Here is the screenshot of the editor attached:
Possibly because you're using screen space canvas. Put the canvas in the world space for field of view to have any effect.

Sprite background image lags on mouse hover

I have basic DOM menu that has sprite background images for the first level of "LI"s.
It works just fine, but I guess there is some problem and instead of switching the image right away on hover it goes blank and after about a second the hover image "appears" (shifts).
That happens only on first hovering. After that it's smooth like it's supposed to be.
Refresh the page and there it is again...
Frustrating...
Here is a link to check it out: http://goo.gl/6FAM
The problem exist on Firefox v3.6.3.
Chrome 5.0.375 and IE 8.0.7600 don't have this issue.
Any ideas?
It's because the hover background image is not loaded until you pass the mouse on the button.
An easy solution is to use CSS sprites, so you will only have 1 image to deal with.