Skip to main content
51 votes
Accepted

Blank 2.2 KB sized PNG costs 2.1 MB in Unity? What does this represent? What to do?

PNG compression works by predicting the next pixel from the pixels that came before. If the image is completely blank, ie. every pixel is exactly the same as the pixel that came before, then that ...
DMGregory's user avatar
  • 139k
13 votes
Accepted

Non-stretching health bar?

Since Canvas > LoadBar > Grass has an Image Component, all you need to do is set the Image Type property to "Filled". Then, the Inspector will ...
liggiorgio's user avatar
  • 5,293
6 votes
Accepted

Screen split in different regions, each with a different scene

This is easy to achieve with viewports. Inside the Inspector settings on the Camera component, you'll find a section labelled "Viewport Rect" that defines the rectangle on screen that this ...
DMGregory's user avatar
  • 139k
5 votes
Accepted

What does this Yellow Outline represent in Unity Text Mesh Pro?

These are 'margins'. In the inspector, you can find them under the 'extra settings' section. This is what the documentation says about them: The Margins values can be used to add some space between ...
troien's user avatar
  • 906
5 votes
Accepted

Seeking a more elegant solution to set buttons so they can increase specific ability level and stats

they can't derive from a base class. Yes, they share many of the same properties but they also share many unique properites. – xmaximix 1 Actually I think you can. This a pattern I use all the time ...
Acme Nerd Games's user avatar
5 votes
Accepted

How do you repeat a tile texture horizontally/vertically in a UI Image?

Unity's UI Image components give you many options to manipulate Textures for UI purposes, as long as such Textures are Sprites. If you want to display other Texture Types, you might use the Raw Image ...
liggiorgio's user avatar
  • 5,293
4 votes
Accepted

Sprite button not triggering "On Click()" event

It looks like you tried to attach a SpriteRenderer to your button to render its visual in your game scene rather than as part of the UI. This means that where the player sees the button, and where ...
DMGregory's user avatar
  • 139k
4 votes
Accepted

Ball always showing in Unity

Thanks to @TomTsagk's comment on the question above, I've found it. It was light probes that needed to be switched off, this is done in the Gizmo menu (in scene view):
Erdal G.'s user avatar
  • 161
3 votes
Accepted

How to call a function in response to a Button's OnSelect event?

Edit: I added the OnSelect version. Note that selecting and highlighting / hovering are two different things. When you hover over your button with mouse, OnPointerEnter will be triggered (if using ...
ezez's user avatar
  • 326
3 votes

How to trigger onclick for Unity Selectable by script?

As you know: button.onClick.Invoke(); Acts like the user has clicked the button, invoking callbacks, but there's no visual effect on the button itself. Do you also ...
davidA's user avatar
  • 141
3 votes
Accepted

C# syntax for "This button is interactable"?

Once you have reference to a Button, you can use Button.interactable to determine if the button is interactable. ...
Gnemlock's user avatar
  • 5,323
3 votes

Do we have events for +/- buttons for a serialized list?

The answer is here - we can use OnValidate event - https://forum.unity.com/threads/do-we-have-events-for-buttons-for-serialized-list.1074768/ ...
Magician Artemka's user avatar
3 votes

Unity text is very blurry. How can I fix it?

Make certain your UI Text object is not inadvertently upscaled. This can happen any number of ways. In my experience, the most common occurrence of this happening is due to generating UI objects from ...
Acme Nerd Games's user avatar
3 votes
Accepted

Thin lines appear differently even though they are the same height

The issue, as other folks have pointed out, is that Unity is doing ~the best it can with the information it has. Because the reference size of your UI and the actual size of the screen are different,...
Mhin Ra's user avatar
  • 46
3 votes
Accepted

How to make a Unity slider sit over evenly spaced points?

This solution sets the dots the same way as the rectFill of the slider with the anchors and should be reactive to the size of the slider. This script is currently placed on the slider. It is ...
Zibelas's user avatar
  • 4,672
3 votes
Accepted

How to create instances of a Unity UI Toolkit template from code?

Solution You can use a VisualTreeAsset. It's a serialized Visual Element Tree. Instantiate it and child the resulting root node to the UIdocument of your scene. Then you can query for elements and ...
Charly's user avatar
  • 752
3 votes
Accepted

In Unity editor, how to import package from github?

You haven't used the correct URL. As described in the repository's README, the correct URL is https://github.com/yasirkula/UnityNativeFilePicker.git The documentation shows that the URL should be to ...
Kevin's user avatar
  • 6,859
3 votes
Accepted

Rendering transparent UI in Linear Color Space

Alright, I sort of lost an entire afternoon to this, but I believe I've got it nailed down now. The problem comes down to the fact that doing arithmetic on colors is a finicky thing, because the ...
PepeOjeda's user avatar
  • 893
2 votes

Working with Screen Space - Overlay canvases

It's like this because UI is usually laid out in pixel coordinates, rather than the game's world coordinate system. I usually just double-click or hit F to center on what I need to look at, and use ...
DMGregory's user avatar
  • 139k
2 votes
Accepted

How can I use Drag handlers (IBeginDragHandler, IEndDragHandler, IDragHandler) with a 2D sprite renderer instead of a UI Image?

Make sure that: You have a Collider2D(BoxCollider2D etc.) added. Physics2DRaycaster added ...
Candid Moon _Max_'s user avatar
2 votes

Overuse of Canvas in Unity3D

Canvas is rendered in the "RenderOverlay" call in he render pipeline. If we are talking about screen overlay the canvas is simply rendered in 2D space over anything previously rendered, which always ...
Sidar's user avatar
  • 3,587
2 votes
Accepted

How would I go about adding a tooltip to a Unity UI Image?

Here is an easy solution for how you get it styled right and working without any need to write extra code. create the Image/ Tooltip you want as a child of your element that should have the tooltip. ...
Zibelas's user avatar
  • 4,672
2 votes
Accepted

What is the Unity 2019.3.5 version of `UnityEngine.UI.Text`?

It's still the same. UnityEngine.UI didn't go away, it's just considered a package now, so its documentation has moved out of the core and into its own sub-page. ...
DMGregory's user avatar
  • 139k
2 votes

What does this Yellow Outline represent in Unity Text Mesh Pro?

It's like a bounding box for the text. If you narrow it the text will overflow, And here in the settings you can change what happens (like text going into a new line or creating dots ex ...)
Milos Romanic's user avatar
2 votes
Accepted

Unity: How to get the visible bounds of an object, i.e. as it is seen from the camera?

As DMGregory pointed out, the solution is quite simple: Just iterate through the vertices of a mesh, convert them from world to screen coordinates and store the min and max values of both x and y axis....
SePröbläm's user avatar
2 votes

Difference between methods - onClick.AddListener and On Click under UI button inspector?

In this particular context there is no good reason to use one over the other. But in general, there are a couple things you might want to consider: Assigning buttons in the inspector requires no ...
Philipp's user avatar
  • 122k
2 votes
Accepted

Strategy for temporarily blocking user input

As DMGregory noted, a Canvas Group is an easy way to control interactivity for a group of UI controls. Just assign the Canvas Group to the parent containing your UI controls, and update the ...
Kevin's user avatar
  • 6,859
2 votes
Accepted

How to get a specific button component

Remember, someObject.GetComponent gets a component attached to someObject. If you don't lead with a specific object to look in, ...
DMGregory's user avatar
  • 139k
2 votes

How do I stop clicks on a button from also triggering my gameplay scripts?

Yeah, actually I've fixed the issue using this EventSystems.current.IsPointerOverGameObject(), here the full doc https://docs.unity3d.com/2018.2/Documentation/...
YouCanCallMe Syarif's user avatar
2 votes
Accepted

Starting a Coroutine after another Coroutine ends

You want to start your fade back to light coroutine after your fade to black loop has finished all of its work, not once in every iteration of the loop (ie. every frame the black fade is supposed to ...
DMGregory's user avatar
  • 139k

Only top scored, non community-wiki answers of a minimum length are eligible