#📲┃ui-ux
1 messages · Page 31 of 1
You need to use Text Mesh Pro asset generator. and generated pixel font should look like this
Yours looks like bitmap font
i think im an idiot
I'm not familiar what would happen if you use it with tmp, that could be it
I put in 8 instead of 16 into the ppu and it works

oh
nevermind :|
i am so lost
its at least working in my test scene now?
Apologies, wont do that again.
Could you tell me what you mean by a well spaced out font? I should clarify that the font uses both JP characters as well as english letters, and both are affected.
Examine your font asset and make sure it has enough spacing, like this one #📲┃ui-ux message
You can also test it with dilate option almost all the way to the left to minimize bleed in. If it fixes it, then you need to space out your asset better
Ah, that is what you mean. Nope, I don't think that is the issue, it renders fine on windows but not android. Don't know how to show the entire thing but it looks like there is decent amount of space between them
If it was an issue with the atlas I would expect that the font would be broken on windows as well
It could render slightly differently. Easy to test
this... was using the wrong font asset
This is windows
Other than that, renderer might not be supporting material shader properly on android.
You can test with simple built-in font on the same device to check that
Already did, built in font works fine
Then test this
You will also note that the size and shape of the boxes drawn in android are the exact same size as the text that is supposed to be rendered.
More testing less arguing
Unfortunately I am not in a possition to test this now (I cant upload builds) but I will do so when I get home.
Sorry, I did not intend to sound argumentitive
If rendering material works fine with another asset, then the asset is the issue. Different devices can render differently. And bleed-in threshold might be closer.
Fair enough.
Also android just might flat out doesn't support atlas of that size, so excluding bleeding-in thing would point out to that.
Well its not android per se, its webgl rendering on android
Students use chromebooks
I noticed this issue when I opened the game on my phone, and I am currently I am testing by opening the webgl build in bluestacks
And I know unity can support Japanese text on android. Plenty of mobile games made with unity on the Japanese market.
WebGL has memory limitations, so it doesn't look good for the atlas size. Still should test that.
So generate it with like 2048x2048 and a padding of like 10 and see if that works?
The weird thing about this issue is it is so specific. WebGL works fine on windows, its only when doing WebGL on android with the new font that there is an issue
These are the setting I used to generate my current atlas
my arrow key keeps going big when im in full screen mode, ots supposed to look like the one on the right
Is your canvas set to scale with screen size in inspector?
That would scale everything. It’s probably an anchoring issue on this object.
If it’s the selected game object in the 2nd image, then anchors are set to stretch.. which isn’t what you’d want with this
Also, don’t work on UI with the game view set to “free aspect”
Yeah ig so show your hierarchy is everything in 1 canvas ?
What is the use case for a canvas in constant physical size? I understand what it does, but is there any practical use case?
I'm sure there are many but let's say you were making some kind of museum exhibit where there's a giant screen and you want to show the scale of a human next to a dinosaur in actual size. It would be helpful to be able to set it to a constant physical size.
(remember Unity has other industrial and artistic uses besides games)
Makes sense, thanks for the example!
One message removed from a suspended account.
I don't believe that has anything to do with graphical raycasting
Ah, well, maybe it does -- it could cause the image to be drawn with a tighter mesh if it has transparent parts at the edges
There is a note about the sprite import settings here
Is it possible to wrap a canvas onto an object?
I'm trying to overlay a canvas onto a bent plane that's meant to represent a screen
Ideally I don't want to use another camera but if I have to then it'll work
how do i make my text look like its going from top to bottom?
anybody know why I cannot find the sorting layer option under text mesh pro's extra settings category?
Shader is Mobile/Distance Field
Unity Version is 2022.3.55f1 LTS
Which component are you looking at
Found the solution, the issue was that non 3D TMP objects seem to not have the Sort Layer option in extra settings! Meant to update here earlier but got dragged into something else.
Yeah because they're UI. The order is determined by hierarchy order
How do you port the text using the package version of TMP from Unity 2022 LTS into the new and built in version that is in Unity 6? I get like 20 errors every time I open my project because the text in my scene is not using the new version of TMP that is built into Unity 6?
Hello everyone 🤗
please help,
bool IsPointerOverUIObject()
{
PointerEventData ped = new PointerEventData(EventSystem.current);
ped.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(ped, results);
foreach (RaycastResult result in results)
{
print(result);
}
return results.Count > 0;
}```
i have this code to check if im clicking on a ui object, cuz i dont want people to place buildings and such when clicking on the ui but its saying im clicking on the ui while i dont think i am? its saying im clicking on my money counter.
there is a gray line in the middle when i select my counter (as seen in the pic) that is way off from the yellow box. and whenever i click on the right half it thinks im clicking on the money counter ui
Press T and change to the UI gizmo tools. That yellow square around your text isn't the RectTransform.. you can see the transform tool is in the center of the rect
The yellow square shows the margins for the TMP, looks like you've manually resized that and left the rect larger
I'm trying to make an Image recognize pointer based on its shape by generating physics shapes for the sprites and then using "Use Sprite Mesh" on the Image. Any ideas why that isn't working for me?
Found a better way of doing it by using Image.alphaHitTestMinimumThreshold
oh i thought that was the size, what do you mean with margins?
I have an issue with text showing as squares? I use the same material and font in other places in my project and they work just fine. Not sure why it doesnt here.
I'm getting this bug that when I'm far from the text it starts showing squares all around the each character of the text. This is probably because of the font (I'm using Gidolinya https://www.1001f...
I'm trying to make content for a scroll view viewport scrollable, but it doesn't seem to want to work. The content inside isn't text, but prefabs that I'm creating that fill up the content area. I'm not sure how to make it scroll unless I make a Text component of the Content to add newlines for each instantiation, but there has to be a better way
Content size fitter to resize the viewport?
I tried that but it didn't seem to work no matter where I put it or what the vertical constraints were set to
https://pastecode.io/s/whossjgc
Here's the code that instantiates the prefabs
TMPro_InputField weird behaviour when click on one inputfield and then click on other mobile keyboard not open properly. see the video
I need some help with my graphics settings since they say low but im on high at first. When you change them its fine but I would like it to say high when u first enter the menu.
I tried changing the orientation of the options, so high on the top and low on the bottom but that just messes it all up and makes it not work instead.
I got it fixed
One message removed from a suspended account.
Hi, I can't figure out why my scene view is using a Solid white background. I have no Skybox set and my camera seems to be set up appropriately.
what render pipeline is this?
HDRP's automatic exposure gets confused by non-lit renderers, like an overlay canvas
it tries to adjust so that the average brightness is correct, but the UI doesn't change in brightness
It's URP
Is there a way to change the sorting order of text using TextMeshProUGUI when all the text is under the same canvas?
what about rendering with sprites outside of the canvas?
One message removed from a suspended account.
So I managed to get hosting UI Toolkit controls inside of uGUI working, the grid looking control is UI toolkit and the blue squares are uGUI. Right now I have it working with Screen Space - Overlay canvas and works when scaled at different resolutions. The next step I guess is to get it working in Screen Space - Camera mode.
I have an HUD on the enemy that appears during runtime, how to make sure the HUD of the enemy isn't influenced by the post processing, otherwise it makes the text more difficult to read
Use Screen Space - Overlay mode on the canvas
Hopefully you don't have world space canvas on enemy
It's a world space canvas, it's displaying the stats of the enemy
simliar to the assassins creed games
It's going to be affected by post processing then since it is rendered by the camera
You might be able to do something with render passes to render after post processing
is it available in Built in? I use that render pipeline
Probably more difficult, I think this is the only option for built in:
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Camera-onPostRender.html
Is this a relatively new project?
it's not
You could also try camera stacking and render the world space ui on a stacked camera
creating 2 cameras and exlude the one that has the post processing?
Yeah essentially have a camera that draws your world normally with post processing, this camera should not draw UI layer. Then have a second camera that only draws the UI layer
I don't think you even need camera stacking for this
I think the camera stacking feature is also not in the built in render pipeline haha, will quickly try to make this
Sorry haven't used built in pipeline in a very long time
no problem
I tried it but seems not to work, the main camera is set to render everything besides the UI and the second should only render UI but it doesn't render it, I've also set it to "don't clear"
Make sure the depth setting on the UI camera is set to a higher value
adjusted this value as well but still no effect unfortunately
here it is, depth in this video is set to 0 but changing the depth value didn't do anything
Did you set every object on the world canvas to the enemy layer or just the root object?
every object is set to enemy layer
I tried with the UI layer as well but same issue
Seems to work for me
what could be the reason it's not working?
Is the UI camera at the right location?
set it to be a child of the main camera and zero out its transform
I've seen that this was the problem, it fixed it but the issue is that the main camera has zoom effects, during aiming or skills which makes the child zoom as well and therefore the UI elements move away.
the main camera follows the player with a cinemachine brain, is it somehow possible to freeze the 2. camera forward movement?
How is the zoom achieved? Is the fov adjusted, if so you'll want to match that on the UI camera
essentially you want most of the settings on both cameras to be in sync
It's driven by an asset, need to check how to resolve this issue
Thanks for the help
I'm not sure how to do this correctly. If you know how to use scroll views please help, video above
See this video
The Speech ui contains the Content Size Fitter, and the Vertical Layout Group, the image contains the Vertical Layout Group. How do I make it so that there isn't so much padding between the text and the speech bubble image?
Why doesn't the TMP UI text or button show up? I've tried changing layers
show the inspector for the TMP when it should be visible - at runtime
"layers" aren't something you'd change with UI
heres the tmp at runtime
Is button the scrolly looking thing? If so the TMP is behind it
UI draws in hierarchy order, from top (first) to bottom (last)
It could also be positioned poorly, those are some large values for it's x/y pos
no, the button is also invisible
it also seems to be in correct position
This red line is your canvas.
You have positioned the TMP off the canvas.
Overlay UI in the scene is HUGE. You don't position it with the game scene.
this is from the middle of the screen.. which puts it out of view if the screen is smaller than those dimensions
My font sizes are usually ~50 to 100. Depending on various factors
ahh changed it. in any case, if the text is then behind the pop up box, how would I move it to the front?
☝️
what gameobject is this image on?
PopUpBox
Is it an image? show the inspector for it
Sprite Renders are for game objects, don't mix SpriteRenderers and UI
You either want to:
- Make the canvas the parent of this. Create an image to assign this sprite to.
OR - Remove the canvas and TMP, and use the 3D TMP instead (RMB -> 3D Object -> TMP Text)
3d TMP is text in world space, it uses a mesh
The text seems to still be behind the image (I went with the TextMeshPro)
dont crop sreenshots, youve cut off useful information
cant see the hierarchy or transform
keep the scale at 1,1,1 - you will get problems with TMP when you dont (use width / height to change the rect size)
Now you're using 3d TMP, your font size will be around 1 (probably the value you had it at before)
ive done roughly around that, but the text is still underneath the image
it works!
what is UI-UX
User interface, User Experience
For further information, just google your exact msg
It looks like the image is in "sliced" mode. It's going to ask for at least enough space to show its corners properly
I forget the exact name, but there is a property on a sliced image that controls the pixel-per-unit multiplier
try increasing that, so that the corners render a little smaller
Does anyone have any tips for making my UI truly pixel perfect? As you can see here, the pixel borders do not stay the same for all frames. I've tried all different kinds of canvas settings
is it ok to have multiple canvases?
googling gives me answers from several years ago, so just wanted to make sure
thought it was for a special beta ui unity made
why is it blue and just go into the texture settings and choose point no filter
Does it behave better on an Overlay canvas?
Hi someone told me there is a guide to adapt screen with every mobile screen, but i don't find it in the pinned message
Hello, i hope this question belongs to this channel. I need to do graphs/charts into UI of application. I think creating the own plots is very time consuming. Is there any other way? i was searching in asset store but for one use, 80 euro is too much.
chatgpt said me, maybe use python, but i dont have any experience with it and im not sure, if this works.
what kind of charts are we talking about?
Aand which UI system (IMGUI, uGUI, UI Toolkit)?
i'll try to ask chat gpt
One basic 2D plot (data,time) and second is little bit specific: column graph in time.
I'm using unity GUI
It's little bit older project. Nowadays I would try to use UI Toolkit
I am trying to build a log book that functions similar to this example (of Call of the Sea) and losing my mind. Is there a magic button that makes TMP flow around images?
Also: Is there a way to get those two nicely aligned columns with the old UI system while also being robust towards different resolutions? I know of layout groups but since the columns do have to be spaced on the pages graphic (which scales as well) it is super hard to make sure nothing wanders in the middle where the pages meet and respect the boundaries to the top/left/bottom/right. Any advice?
You would do this with layout groups. Two parent layout groups would be the pages, which wouldn't allow wondering to the middle
Something like this
Red - vertical
Blue - horizontal
Green - vertical
Yes I understand that but have a hard time making sure the red boxes stay where they are when it comes to different resolutions. I.e. it works on 16:9 but not anymore on 16:10. Adjusting the slider in the canvas scaler that differentiates between height/width matching also does not solve the problem.
(btw thanks for making the arcade vehicle controller I wrote my master thesis using it <3)
If the book is UI too, should be doable - if it's not... it's doable, but no idea about it
heh, good to know - glad it was of use!
hello! i am writing an editor tool to automate the transfer of data from Dialogues(scriptable object) to the Unity Localization System and vice versa. It almost works, but the LocalizationTablesWindow doesn't refresh until i press the New Entry button, or i close and reopen the window. Is there a way to automate this process without messing up the layout?
LocalizationTablesWindow window = EditorWindow.GetWindow<LocalizationTablesWindow>();
window.Close();
window = EditorWindow.GetWindow<LocalizationTablesWindow>();
window.Show();```
Calling this code after modifying the SharedTableData works, but the window loses the docking state
For regular line graphs, I have used the line renderer and trail renderer earlier. For bar graphs, I would probably make my own little system, there's for sure existing solutions out there though, however I'm not aware of any free ones
Haven't looked into it recently so there very well might be a free one too
how bad is the unity vector graphics package (experimental) ?
the result looks super pixelated and reading online they seem to say it's normal
any alternatives?
looking for the "infinite resolution" svgs provide, right now it looks worst than the rest of the scene
I don't remember having that problem. I know there are a few different ways to import SVGs..
I'm not currently using it because I switched how I create my graphics (winding up back with rasters)
Should be good as long as you set the target resolution properly
Or use the advanced settings to change the sampling settings
Just know that the vector graphics package doesn't directly render SVGs. All it does is rasterize them ahead of time into regular textures.
Yeah -- it can't magically make your Image components start doing vector rendering
Is there a way to get a non-worldspace canvas to render into multiple cameras?
optionally, is there a way to get a child canvas to render into a different camera than the parent canvas?
Overlay doesn't render on ANY cameras and Screen Space Camera renders only on one camera.
No
What's the context?
I have a setup where my UI is composed of a lot of nested canvases
I'm using a ui blur tool, that requires some of that UI (the one that's supposed to be blurred) to be rendered onto a separate camera than the one with blur components
and I'm stuck
ok - how about parent canvas is set to camera, child canvas is overlay? is at least that possible? Or am I stuck with having to split them
Only the main canvas gets a render mode afaik
I am using the Pixel Perfect Camera with the URP. In order to get my UI to stop jittering when the camera moved I had to set up a second Camera and set the render type to Overlay, and then add it to the Main Camera's Stack. However, the Pixel perfect Camera gives this error message.
From what I've seen online others get this but don't notice any issues. I'm curious if anyone else has had experience with this as I'm worried it'll appear fine, but down the road I'll suddenly discover the issue and it'll be a big problem somehow.
I'm hoping this is some legacy thing and a non-issue 🤞
alright so here's more details about the SVGImage issue I was talking about yesterday
this is using the unity Vector Graphics package (experimental) inside a worldspace canvas
i've tried messing around with the import settings but I think that might just be how it is after reading this:
i would expect smooth lines from any distance since it's an svg
right so as mentioned yesterday it's pre-rasterized. So you'll have to get a high enough resolution raster image for all of your expected viewing distances
it's not a true vector graphics renderer
World space canvas itself has resolution concerns too
that looks like an aliasing issue; do you have mipmaps enabled?
i forget what the vector graphic importer settings look like
There is no efficient way to render curves efficiently when they have to be rasterized every frame. The best thing you can do is using an SDF renderer like textmesh pro. Using mips and rendering an oversized texture from an svg is a wasteful technique that effectively works the same way.
good to know, and sorry totally missed the reply yday, only saw fen's
i'll look into maybe avoiding world space (which i think the only way is using sprite renderer with the svg sprite)
there's also another package i found on github, used to be paid but the author opensourced it, maybe the rendering would be smoother?
i tried reading on it a bit but i think just testing it is how i'll find out
from the link i posted i think it just wont do antialiasing on ui elements, not sure about mipmaps
here's what the importer looks like
picking something else than vector sprite gives different options
although rasterizing at high res creates very large textures which is an issue for my project
you can get antialiasing on ui elements if you use a screen space - camera canvas and set up antialiasing on the camera it's being rendered on
i tried something similar with a render texture (cause of the unity's author recommendation in the thread i linked) but i guess the render texture is probably not needed
it seemed slightly better with that technique but still meh
maybe i'll try without the render texture the way u said
realized the issue with that is i can't place the element in world space
(without using a render texutre)
What is the use case for this thing
2d character in a 3d world
Wouldn't you want a SpriteRenderer for that?
rather than UI?
yep, that was my first attempt, lines are not as smooth as i hoped for with it though
although no technique looked super nice for me yet
i think the screenshot i posted was with the sprite renderer
it's kinda annoying me that the 3d looks much better than an svg image
i was expecting the opposite or atleast equal aliasing/pixelation
also i tried the thing from github, it did render a simple material icon svg properly but didn't render my drawing well
so i think i'm all in on the unity svg renderer
if i'm not mistaken, seems like theses two values have the biggest impact on the end result
not quite sure what to do with advanced tesselation
mostly pixels per unit, not sure if there's a high cost of putting in a big number there
some people also talk about converting the svg to a mesh instead
nvm, kept doing some testing and struggle to see a difference between the different vector sprite import settings
i think advanced -> step distance is the only (main) thing that matters
does seem to affect file size though
do other sprites render without the aliasing?
from testing does not seem like it's aliasing per say, probably just do to what everyone is saying, in the end it always gets rasterized so it never truly looks like an svg
Is there a way I can allow the player to scale the UI in like manually, in runtime?
You know, in like if they were dragging the blue dots of the UI scale
Modify the scale on the canvas scaler?
You know in like WoW that you can literally drag windows and resize them? How could I do that?
A complicated system of ui elements and dragging and dropping code.
If your windows are free-floating, it sounds like it'd be pretty easy
you just need to get a handle on how RectTransform works
notably, you'd need to adjust its size and position simultaneously
I am basically now trying to have like dps meter type thingy working and right now I am trying to make sure the proportions for the panel are right, and I guessed the best way to do that if I allow the player to resize it. I am kinda having troubles trying to make it not overlap with stuff
Basically this is the extend of what I would want it to do
How hard would that be?
It might be useful to put the inspector into debug mode, so that you can see the actual properties changing as you resize the RectTransform
the anchoredPosition and sizeDelta change as I resize something with the Rect tool
What else is changing other than the size and possition?
Just those two things -- well, the local position changes too, but it's calculated from those two properties
I mean.... sounds like superhard if I have to like calculate a scale and position from a mouse position tbh
Record the position of the opposite corner, then use that to figure out a rect
the rect will touch:
- the opposite corner's position (which never changes)
- the mouse cursor
I could get the difference in X and Y from the bottom left corner but... doesn't they use like different units of meassure?
Ther Canvas is pixels right?
you just need to get into the right coordinate space!
I forget in which space the anchored position and size delta properties are defined..
So.... uh.... this is a boolean that tells you if the screenPoint is inside the plane of the RectTransform???
I do not understand
no, it takes a point on the screen and gives you a point in the local space of a RectTransform
it's possible for this to fail (maybe it's a world-space UI that's perpendicular to the camera?)
hence the bool
yeah
I want to say the anchored position is defined in the space of the parent (or in world-space, if you have no parent)
I haven't fussed with this stuff in a while, though
Yeah, me even less lol
So I could get the possition of the mouse in local space, then translate to space in Rect transform, and compare the X and Y from the anchor point on the bottom left corner to change the width and height on via script
Cool
a lot of things become easier once you find the correct coordinate space
(instead of trying to approximate it by just slamming in screen coordinates or something)
@swift basin once u do this you may want to package it up to keep for later..
that'd be a system worth keeping
I mean, I don't intend in erasing anything I do
lol.. oh well if its your only project, nevermind me
can someone tell me why cani see my blocks in scene window but not in game mode?
@mighty ridgehello! sorry for pinging but can you help me asap
they're probably not in view of the game camera
- What are they made of? (SpriteRenderer? UI Image?)
- What position are they in?
spriterenderer
wdym position?
if i click on those spaces the blocks appear
Can you answert the clarifying questions?
What is that background made of?
And what position is everything in?
And what position is your camera in?
bg is image
ok the BG is a UI image
on a canvas
presumably in overlay mode
overlay canvases draw on top of everything in the game
that's why you can't see anything
disable it for a second
Oh it's a world space canvas?
Anyway - that BG image thing is just in front of your sprites that's what it seems
no cuz when i click those spaces where sprites need to be, the sprites appear
What's the hierarchy look like?
Are the sprites a child of something?
yes empty game objects
Which are positioned where?
what's the z axis position
all the way up the hierarchy
yep that'll do it
thank you
chat, why is my layout group fighting with my elements?
i'm embarking on making my 16:9 UI responsive to other aspect ratios but a reocurring issue is how layout groups react to the "Content" gameobject being changed in width (which is what changes on different aspect ratios), they respond by setting width to 0, anyone know why (??)
Try ticking 'control child size' on the layout group
I'm new to Unity, I've only used UI Toolkit because it is familiar to me as a web dev
I am considering using Canvases for player HUD. Is it better to have the same duplicated canvases across every scene for my HUD or should it be a single set of canvases kept in my UI singleton? What is the best practise for avoiding repetition in canvases
The real question is:
- Do you include an instance of your prefab in each scene?
vs - Do you use a bootstrap scene and either additively load the instance or use DDOL to carry it between scenes?
Either way, you'd use a prefab
I use a bootstrap scene and use DDOL to carry. So it is advisable to use a prefab set of canvases to carry UI elements across playable scenes in this case?
sure
Hello, I need help with TextMeshProUGUI rendering Devanagari fonts
There is this asset which does it
But the website of the creator is down
Im not sure if its worth putting in so much money to get it, if it doesnt work
Is there an alternative way to implement this?
For those unfamiliar with matras, they are vowel modifiers that attach to consonants. Unlike English, where vowels are separate letters, Hindi modifies consonants using matras, which can appear before, after, above, or below a character.
how do they render atm?
hmm i kinda see whats wrong. Have you tried with tmp v 3.2?
i cant even find a font that support these characters on google fonts.
I dont know, check the package manager
eh, something weird happened, wasnt able to sent message
it isnt there in the package manager
2 mins
will check again
TMP is built in with U6 I believe - theres no package for it
T_T
Including TMP without a package?
Probably should have been done a long time ago, its the default text and if you want to be doing UI is what should be used.
that is true but i've certainly had problems with tmp in the past and its been useful to update it seperate from the editor
That is a good point - cant think of ever doing that personally, but is useful
can some one please tell me what im doing wrong here. Im trying to use the horizontal layout i made the width 360, the text width is 260 and the circle image is 80 the height of all 3 are 100. but it does not put them centered inline.
- Use the rect tool
- Show the configuration of the layout group
- Show the actual graphical element here
I'm trying to add a Scroll View to my UI, I created this from the menu, so it came with the Viewport, and Content Game Objects.
I have some text which I was trying to scroll through vertically.
If I choose Elastic (Movement Type), the scroll bounces back to the starting point when I let go.
If I chose Unrestricted, I can scroll out out of bounds of the text so it disappears.
If I chose Clamped, it doesn't scroll.
I can record the screen to show the examples if it helps.
Can someone please help with how I allow my scrolling as I would expect?
- To stay at the location when I let go.
- To only be able to scroll to the top and bottom of the text.
Size of the content object must be larger than the frame so it has something to scroll. If you attaching something to content you need to use content size fitter for it to resize it matching content. See tutorials how to work with it.
any ideas why scene view darker than game view?
Lighting on/off, post processing, gamma/linear color space.
Turning post processing off in scene view fixed it thank you
Note that the scene view will incorrectly display an Overlay canvas with post-processing
that's why turning it off made it consistent
Hi! Need help with toggles
I have a bunch of toggles in my scene. Instead of having a separate function for each, I made it take a string with the toggle so I can make a case switch with each possible result
The problem is that toggles only call On Value Changed (bool), and apparently I can't pass both a bool and a string into my function. If my function is public void SetTags(string tag) it works, but if it's public void SetTags (bool check, string tag) it suddenly stops showing up on the editor
Not totally sure of your setup, but if the string is the toggle name or something, you can make the toggle call SetTags(bool) and then in that function send the string you want. Like the gameobject name.
Any clue how to fix this scrollview error
Elastic just pulls it back
when I do have content that should allow it to scroll
Make sure the content rect is big enough to hold all of the content. The scroller only cares about that rect, but what's in it.
Thanks! It could be my mistake, but I either did not come across it, or there was a lack of the UI tutorials on Unity Learn.
My mistake was creating a child Text - TMP GameObject, when the solution was to simply add a TMP Text(UI) component to the Content GameObject.
This person (https://www.youtube.com/@ChristinaCreatesGames) helped explain it, and has quite a few UI related tutorials which might help others.
The defualt content object doesn't have a vertical layout group
This means that it has no clue how much space its children need
(it also needs a Content Size Fitter to make it actually change in size)
Attaching the text component directly to the Content object does work, too (as long as you only need that one text component!)
Im trying to open up the unity ui editor and it refuses to let me do so. any help pls?
I got this open, but now when im trying to get my .button:hover to work on more than one button, it wont animate?
when my mouse is here, it works. not on any of the other buttons tho
i used a script to check where my mouse position was hitting and it hit the button fine... i dont know, if you want more details with screenshots please follow the link it not too much but its already there
but in short on focused mode it does not recognize hover and click on the mouse, but on maximised everything works fine. and also touch works fine for click in any mode
hmm.. i moved on from that part, and now im trying to make it when i hit the start button, i go into the other scene, but it doesnt seem to wanna work now
does it start working if you maximize the game view after entering play mode?
you can double-click on the game tab to maximize the window
yes, if i maximise (starting in focused mode) works fine
What else is in your hierarchy?
The script you used earlier tells you all of the things that one graphic raycaster hits, but it's possible that you have another canvas with something that's eating the raycast
no i dont have any more canvas
i have a few objects but no more canvas, no more event systems
its strange, if i touch the button, with my touchscreen, it works
so i dont know why would it "eat" the raycast with the mouse
only on focused mode
and what about the reverse? does it stop working when you un-maximize the window?
yes
to rule this out, delete everything that isn't the canvas, event system, or camera (in play mode, of course)
the behaviour maintains
i have this tv static generator, its using a quad is using scale the only way to control the size? would there be a better way?
that's quite interesting...
can I see the inspector for the canvas and the button?
so the static is small. the only way to make it bigger is to use scale. feels like increasing the scale is the wrong way to do it
only way i can get it to fill is scale
you should be using an Image for this, not a mesh renderer
a RawImage, specifically
that'd let you use a render texture directly
(although it looks like the "TV Texture Generator" wants to modify an entire material, rather than just drawing to a Renderexture)
ok cheers
maybe i should report as a bug.. i dont know what else to try, i am not currently focusing on that since i can keep going, its just anoying that i cant test my button normally in the focused window
if the material references a RenderTexture, you can just leave that material unused
and then reference its RenderTexture from a RawImage
(this all assumes a render texture is involved)
i had to take my mind away for a bit so i made this:
using UnityEngine;
[ExecuteInEditMode]
public class QuadResizer : MonoBehaviour
{
[SerializeField]
MeshFilter filter;
[SerializeField]
Rect rect = new(0, 0, 1, 1);
Rect previousRect;
void Awake()
{
previousRect = rect;
}
void Update()
{
if (rect == previousRect)
{
return;
}
var vertices = filter.sharedMesh.vertices;
vertices[0].x = rect.x;
vertices[0].y = rect.y;
vertices[1].x = rect.x + rect.width;
vertices[1].y = rect.y;
vertices[2].x = rect.x;
vertices[2].y = rect.y + rect.height;
vertices[3].x = rect.x + rect.width;
vertices[3].y = rect.y + rect.height;
filter.sharedMesh.vertices = vertices;
previousRect = rect;
}
}
if you add this to your quad object you can adjust the vertices, i have no idea if this is the same as scaling, and as fen said you might have better options
ah, the TV Texture Generator script is creating a render texture and then assigning it to the material
If you can modify the script a bit, you can add a RawImage field, then have it assign the render texture to the mainTexture property of the raw image when it sets itself up
i will try this if what fen said doesnt work for me(meaning i cant get it to work) thank you
ok ill try that
It should have something very roughly like this:
RenderTexture rt = new RenderTexture(2560, 1440, 0, ...);
material.SetTexture("_MainText", rt);
sure, this seems "dirty" it just doesnt change the scale but i assume the material will stretch anyway idk
that's where you'd assign the render texture into the RawImage
awesome thank you
somthing is alittle off, the screen is now black but i can see the texture preview
i did ask chat gpt for alittle help, as im not to clued up on this.
idk if you ca ntry the component i shared, as i said i dont have much hope but i am curious and it doesnt take much to test (just add new component on the original quad object, if it doesnt work at first just set the filter field and reload scene as i assign a value in the awake method)
yh i did try that it didnt strech it at all
if its the texture you might need to apply normals or bounds after modifying te vertices
ah ok ill give that another look at in the morning, cheers
what is that? i see you have the component but i dont know what is happening if you dont explain, i tested the script and it does modify a quad, but i didnt have texture, you might need to add a line of code or two after the vertices are modified, such as some of these:
filter.sharedMesh.RecalculateBounds();
filter.sharedMesh.RecalculateNormals();
filter.sharedMesh.RecalculateTangents();
filter.sharedMesh.RecalculateUVDistributionMetrics();```
if its not working at all maybe need to reload scene for first time or change code to avoid the awake logic
Ah yes sorry, it does seem to set the quad to 2560x1440
ok, and if the green is the quad and its not at the correct position just set the x and y to center
yh so your script does work, so will the width and height be what the scales would have been i thought it was 2560x1440 for my screen size. 1, 1 ust makes it the size it originaly was
the transform position is the origin, the x and y will offset that, width and height will "scale" but without modifying transform scale. its like if you imported a quad with a different size
the issue with this approach is that i think will be effectively the same as using scale 😅
im still having some issues making the play button open a new scene. any help?
- What did you try?
- What went wrong?
And by "play button" do you mean the Start button pictured?
or something else?
yes
This looks like it's probably a #🧰┃ui-toolkit question tbh
ive tried following a tutorial listed by the professor, and editing the code for fixes and checks, but it just wont swap. i even made the scene name changed to have no spaes in case it didnt read it but it still wont swap
ah- sorry-
ok well - you would need to show us what you tried
and also - make sure your console window is open so you can see any logs and errors
Show your Support & Get Exclusive Benefits on Patreon (Including Access to this tutorial Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH
--
If you've been intimidated to try UI Toolkit, or have been wondering if you should switch to it (or are just curious how to...
it was this one that was listed-
when i tap on it there, nothing in the logs comes up
I mean you would have to show us YOUR code
one moment, let me forward my thing to the right chat
i cant click my button
Hello everyone! I was wonderinf yall could maybe help me out. I have the GREEN UI objects and I want to make their POS be the same as the YELLOW object.
As you can see they are in different hierarchies and it makes it hard to make their position be the same.
The object is instantiated at runtime so i can manually place it there.
Can anyone provide some guidance?
I tried various options but used AI so i dont fully understand the anchored postition and point to world space jargan when it comes to UI.
Not sure how to search for this, or where to ask for this since it's more of a design question. How can I signify that a text is coming from a character outside the screen? I know I've seen this in games but can't quite remember different ways of doing this.
You could have it subtly move away from the edge of the screen as it appears
yeah definitely think that's gonna help, I feel like I'll probably need more than that though
will start experimenting with atleast that
thank you sorry i feel asleep. yh alworking good now thanks for you help
good to know
Speach bubble, or at least part of one, that points to off screen
If I have a ui panel that i want to display items on, how would i make them not spawn on top of each other? I assume I could just change the spawning pos by a set value but is there a quicker way to do it?
What do you mean 'on top of each other'? If you mean one of them overlapping the other, use Sorting Layers.
consider a layout group
a VerticalLayoutGroup set to control child size (and to not force-expand children) will arrange them vertically
How can I get my sliders to glow / sprite swap like my dropdown? during highlighth and select https://gyazo.com/3119d466c7f44d7f86348e636c4c1473
Thanks, thats exactly what i needed
hi, the yellow box is a container and i am trying to add sprite into it, but its invisible, what am i doing wrong?
what is it?
SpriteRenderer or UI Image?
SpriteRenderer
SpriteRenderer is not for UI
that's for game world objects
use the Image component
Anyone got any ideas / resources for functioning radial slider bars? looking to spice up the look of the normal sliderbars, knobs would work aswell. prefferably free resources
Unity's built -in image component can do radial fill
thats wierd, i dont have those options
you do
you need to assign a sprite first to the "source image" field
then set the image type to "filled"
ahh yeah i see
This makes radial value display easy enough, however i really wanted to make it interactable, like a slider. I suppose its possible but its gonna take time i dont really have
found sliders that work radially, but it still a "left-to-right" dragging action
Yeah you would probably need some custom code for that
wouldn't be super hard I think - just a Vector3.SignedAngle call basically between the mouse position and the center of the slider
i dont think it'd be too difficult no?
yeah thats what i thought
wierd that theres no assets or stuff when i search for it
I guess it's just not that common of a use case
I can't remember ever in my life dealing with a radial/dial style interactable UI in a video game
In real life plenty sure
yeah for dragging ur mouse around a radial is gonna be that much more annoying i guess
Yeah I think it would be sort of weird/annoying lol except as like a very stylized thing
just looking for ways to spice up my UI tbh from just buttons, inputfields and sliders
I could see a game where you're driving an 80s car around and there's a knob in the car to turn the radio volume up or something lol
mysummercar type game fr
I think it'd be better to spice it up visually rather than fundamentally chjanging the interaction style maybe?
Are these just for like a settings menu?
ah no, im using unity for a rather unique scenario, working with a company to gamify / spice up one of their tools. but it could be compared to a settings menu i guess
but yeah spicing them up visually brings the risk of too much distraction, so im trying everything to introduce a certain feel without too much visual stimulus
ah and its for my undergraduate project, student boio here
or at the very least a new feel
but i suppose im gonna have to do this with stuff thats external to the buttons and stuff itself for now
Dials usually get rotated with a horizontal or vertical mouse movement
Hey I've been trying to figure this out for a while now, I feel like this should be very simple but all the forum posts about this exact thing just don't work for me...
I want a vertical layout group that holds a number of children
each child holds a variable height textbox
the textbox is simply a background image with text in front of it
like this:
I just can't seem to get my head around it,
I've made a textbox that scales its background image depending on its child TMP using a content size fitter,
but when I try to put this in my vertical layout group it gets fussy about children of layout groups cannot have content size fitter and it does not do the layout properly
Content Size Fitter should only be used if your parent doesn't control your size
Your hierarchy should look like this
- Root <-- ContentSizeFitter, VerticalLayoutGroup
- Box <-- Image, VerticalLayoutGroup
- Message <- TextMeshProUGUI
- repeat many times
- Box <-- Image, VerticalLayoutGroup
Every vertical layout group should be set to control child size. Uncheck the "force expand" options.
Set the content size fitter to provide the preferred amount of vertical space
You can leave the horizontal size unconstrained if you want a fixed width
I have 2 images (Tooltip and Soda) which are overlapping, the panel is a child of the soda on the left. How can I stop them from overlapping?
Anchor the tooltip to the bottom right, rather than the center
Additionally, set the tooltip's pivot point to the top left
Here's how it should look.
And here's how that'll look. The "tooltip" is the red panel here
You might want to use the bottom center instead
Oh, you're talking about how the tooltip appears under the second soda can
Yep
You'll have to place the tooltip after all of the other images in the hierarchy
so it won't be a child of the soda can image
How would I do it on a prefab?
Does every single soda can icon have its own tooltip attached to it?
Yeah
If so, I'd get rid of that. Use a single tooltip object that you position via script
Thanks, that worked. Forgot to respond
Is it actually worth using svg in ui at all? Seems like it comes out all jagged and distorted. Wondering if it’s better to just use vector for the art but export to png at the intended size instead
switch it off from the "Vector Sprite" import mode and you can get roughly that
i forget the exact names of the other modes
one will just create a texture
its doing that in "UI Toolkit Vector" mode. not using sprite
Hello, can I replace the blinking " | " in an input field with an underscore ?
That's called the 'caret' - which might help you in you googling
Can I make it so that the content in my Scroll View is aligned with the top instead of the center of my " Content " game object ?
Of course
Change the anchor
Hi whats the best way to use unity events for buttons my current set up is like this for the buttons are like this
or tho this works as soon as i move the mouse out side of these buttons none are no longer highlighted. in the past i did somthing like this to set the buttons. EventSystem.current.SetSelectedGameObject(null); EventSystem.current.SetSelectedGameObject(controllerButton); I was just wondering if im making it to complicated and unity ships with a tool to handle this. because if i do it this way - again i got an issue of when my mouse hovers on them and when they dont
Not totally sure what you're trying to do. Do you want buttons to remain highlighted after your cursor leaves their boundaries?
I want to remake the HUD for my game to fit better in the environment, any ideas?
Hey friends, I'm working on an extremely ui-heavy mobile game, and I have an interesting task.
Turns out we need support for not only phones, but tablets as well - including portrait AND landscape.
For reference, I'm using the old ui system, not uitoolkit.
How do you all here tend to approach something like this?
Different prefabs based on aspect ratio/orientation? Or fight with the layout system?
Something else?
Use the resolution picker in scene view to test different resolutions and set up anchoring etc properly
In some cases you might want a totally different layout for portrait vs landscape but it depends
i resolved it thanks
Someone know ow to fix it?
Did you read the message in the link I've provided?
This is the link #📲┃ui-ux message
Re-create asset with proper settings accounting for that.
lol now the text look like this
Make sure you are using TMP Font Asset creator not regular one and there's atlas preview as well. For regular font 512 usually enough too.
make sure u have good padding values..
sometimes using a smaller atlas (like 512) fixes it..
hmm i think i found the problem
In one scene the text looks good and in another scene it looks like this:
theres also different shaders u can try out Bitmap has worked for me really good for crisp text
but when i change "cull mode" to front its look like this:
oh welp theres yet another solution ill have to remember or look into lol
its weird.. when i first had this issue i had used the biggest resolution there was..
it turned out to be better when i tried lower resolutions..
so now i only use 512
oh wait
in the scene:
in the game
TMP doesn't like small values. So the scale of the RectTransform should be 1,1,1 and the font size needs to be > 1
something i wish id know way sooner
also not sure if it would be a good idea here then to use ugui in tandem with ui toolkit, as i'm not exactly sure what the intended relation between these two are...
Move this question to #🧰┃ui-toolkit (delete from here so you don’t get told off for cross posting)
In answer to this.. UITK is a complete replacement for UGUI, they’re not meant to be used together.
“Soon” UGUI will be deprecated and become legacy
Hello everyone, me and my teammates are currently debating how to architect our Unity UI. (Not toolkit) We are leaning towards having each UI View in it's own scene with it's own canvas. The main benefit being you can hit play and the UI is quickly fully interactive and quick to debug while you develop. I and another teammate find the idea of using scenes for views kinda repulsive and don't really know why. We can't really find any reason not to.
In the case we need to instantiate multiple of the same view, such as generic popups, we can just manage them under a single view.
So, looking for reasons this might be a bad or good idea.
What about prefabs instead of scenes?
That is what we are moving away from
Scenes can be a little cumbersone to deal with in the editor
but there are some advantages like async loading
You can async load prefabs in addressables too though.
Indeed with a little more setup
The argument is prefabs vs scenes. I prefer prefabs but can't really say why.
What's the benefit of scenes
The main benefit being you can hit play and the UI is quickly fully interactive and quick to debug while you develop.
This one is the only one we have so far
Couldn't you achieve that for your prefabs pretty easily too? Something like a UI tester scene?
Faster iteration on testing and development
You could just make a little helper script that, for example, lets you pick which UI you want to edit from a dropdown
We could but the question is why put the extra effort into it?
populated via AssetDatabase calls
The benefit would be that you can just use prefabs
instead of scenes
and not have to deal with scenes
I don't have a horse in this race really, just pointing out options
Yeah and again, I prefer prefabs. Trying to look for a good argument not to do scenes
the main argument against scenes is they are cumbersome to load and unload and manage in code compared with prefabs
they're also more annoying to edit
prefabs get prefab mode
So far I have none other than maybe multiple canvases vs a single root canvas with subcanvases might have slightly worse rendering?
you have to actually load a scene in the editor to edit it
You have to load prefabs too in order to edit them.
you'll also need to keep your build scene list up to date for the UI scenes
not really you can just use prefab mode
You can change a few things on the root of the prefab via the inspector but anything inside you have to open the prefab.
So double click prefab vs double click scene?
Editing a scene -> double click prefab -> hit the back arrow to go back to the scene
there is no back button when you load a scene
Yeah but the scene only contains that specific view. It's like a prefab but not haha.
You can also reference prefabs in the inspector
It's a crazy idea and was caught off guard by it
True but our UI system only cares about the BaseView component on the root game object.
Prefabs also get prefab variants
another huge advantage that scenes don't have
I think those two alone give prefabs a huge edge. Variants and the ability to reference in the inspector
Yeah true, though our team does not want to have variants of our views. Only components like buttons, text fields etc.
If you have some BaseView component that's a great case for prefab variants.
There would be a base prefab with that component and all the rest would be variants of it
Yeah, in theory it sounds great but we've noticed that people try to reuse views too much and they become complicated and maintenance hell with variants.
Anyway again, not my decision but I think those are some good reasons.
I think that's because views are too specific in how they need to work. Though components like buttons and stuff it makes sense to make small changes and have variants.
I really haven't heard any benefit to scenes other than the ability to hit play and run the UI scene alone. Which doesn't seem all that useful to me tbh
Yeah, thanks for trying. I'v already argued these things but valid points against it keep getting raised so we might just have to try it and see how it goes.
ikr
This is also handled automatically by our build pipeline through addressables.
anyone know why scrollbar steps are capped at 11?
at least switching to debug mode lets me set it to higher than 11
i have the character health bars as a canvas in world space as a child of the actual unit. it's not too bad in the screenshot here but sometimes larger units can block the view of the health bar more and im wondering what i can do about that short of switching to a screen overlay canvas. any recommendations? thanks
thanks!
is it weird i think that's actually nicer to look at than the other way around?
Anyway - you can render them on a separate overlay camera rather than the main camera
i dont mind when it's a little blocked like the screenshot, but sometimes the taller units block it more like this. maybe ill just up the y position on the healthbars a bit and see how that looks
I was testing out button.clickedWithEventInfo and was wondering if there was a reason why my originalMousePosition debug console always outputs (0, 0, 0)
For context I have three buttons in different positions on the same ui document
probably easy to answer, I had a break from Unity and can't remember:
I have the attached sprite. When setting the GameObject to Simple I get second picture. Sliced I get third picture. Scale is X1 Y1.
How do I make the border stick to it's size and adjust to my tiling when changing it's size?
You're changing the scale, do not do this. Leave the scale at 1,1,1 and change the width/ height values on the recttrasnform
also press T and use the UI gizmo tools when working with UI
I have not touched the scale, it's X1 Y1. I only changed the Canvas Scale to X.02 Y.02 for world space.
That is stretched to its parent, what is the parent rect like
@low pike
first set it to sliced, that's the correct setting
what's the image component look like now you've set it to sliced
this is the current status
click 'fill center'
Though, thinking about it - fill center probably fills the square in the middle, not the "center" between the slices 🤦♂️
yea this didnt help
I have set this up multiple times in past projects I really don't understand what I did wrong this time
Things look right.. but I need an image to play around with - rather than going back and forth
Why is my toggle not passing onto the method the bool value of Is On, and instead, is passing the value of that little square under the method?
{
if (is2024) toggledEntries.SetActive(false);
if (!is2024) toggledEntries.SetActive(true);
}```
you gotta choose a dynamic variable version, its at the top when you choose the method
Ohhh ok ! Thanks
Should I use LeanTween for UI? or is Animator ok for UI now?
many tutorials said animator is a bit expensive on the system, but its been years so idk if that talk is still up to date
using an animator for UI animations just sounds annoying
Ye but like is it bad?
Heavy on the system I mean
If not optimized properly then yes. But why not use lean tweens? They’re more organized and efficient
Still learning everything, so I'm aiming for best practices with stuff
Still very much a beginner
lean tweens are your best option since they are very easy to edit via code
Animators make sense for a single "thing" that has a complex series of animation states it can be in
UI is more like...50 tiny things, with only a few states
Anyone have any guesses as to why this localized text is showing two lines in the same place? I had this issue before a while ago but I don't remember what fixed it 😔
If you're using Text Mesh Pro, possibly have the "Paragraph" setting to a negative value?
hi, my circle gameobjects have text in them. how can i center their texts so that they're not centered in the middle of the screen?
show me the hierarchy, as well as the inspectors for the circle object and text object
okay, here it is
Don’t use sprite renderers. The canvas has no idea what to do with those
They’re rendering separately
You should be using an Image component to draw sprites in a UI
okay, i have replaced the circles with images and now the text is centered properly but the circles aren't spawning from the tiles i click them from
You are probably trying to position the images at the world-space position that you clicked at
Notice how, in the scene view, an overlay canvas looks really big -- much larger than the camera
yeah
For an overlay canvas, you can literally just set the position of the object's Transform to the screen position of the mouse
More generally, you'll want to use this:
one pixel on the screen is one world unit on the canvas, hence why that works
ohh okay
im just a bit confused here tho. what does this bool do that can help me spawn the circles at the positions i click them from?
bool Returns true if the plane of the RectTransform is hit, regardless of whether the point is inside the rectangle.
This just tells you if the method succeeded
in some cases, it's possible to miss the rectangle entirely
e.g. on a world-space UI
The actual result goes into an out parameter
public void GiveMeFive(out int num) {
num = 5;
}
...
int x;
GiveMeFive(out x); // x is now 5
They're useful for when a function wants to give you several things
public bool TryGetNum(out int num) {
if (canGiveNumbers) {
num = 123;
return true;
} else {
num = 0;
return false;
}
}
very commonly seen in "Try"-style methods
This method takes a rect transform and a screen point, then finds a world-space point that's on the rectangle
and then i can use that world-space point to see where i should spawn the circle right?
Yes.
pretty much just circleObj.transform.position = worldPos;
Personally, I would do it like this:
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(holder, screenPoint, null, out var point))
{
var circleObj = Instantiate(circlePrefab, holder);
circleObj.transform.localPosition = point;
}
where holder is the RectTransform you're parenting the circles to
note that I used ScreenPointToLocalPointInRectangle here
which gives a local position
the circle are all parented to their own world space canvas so that would be the holder, right?
It'd work the same with WorldPoint; you'd just set position instead of worldPosition
Yeah, whatever they need to live under
Reference it as a RectTransform
okay, one last thing sorry, im a bit unsure of what screenpoint is. would that be a transform.position of the tile im spawning from?
Ah, I think I’ve misunderstood what you’re doing. Are you have a tilemap?
no, i just have some square gameobjects laid out in a checkerboard pattern and whenever i click them they spawn the circle objects. i just call them tiles, sorry for the misunderstanding
and are those tiles part of the UI?
or are they using SpriteRenderers?
they are using sprite renderers
so you need to find a position on the UI that'll match the world position of the tile
you can first turn the tile's position into a screen position with Camera.main.WorldToScreenPoint
and then use that screen point to find the right position on the UI
it's a bit awkward because the tiles aren't part of the UI
(also, resizing the window would then cause all of the spawned objects to slide around!)
you may want to keep everything in the UI or out of the UI
rather than mixing the two
oh okay good to know
so then screenpoint would just be the rect transform of the tile i clicked since they're already ui right?
If you put the tiles into your UI, then yes.
You could also just use the tile's position at that point
(since it'll be on the same canvas as the circles)
okay, i've done everything now and it works! thank you for explaining everything so thoroughly!
Looks like the margin settings are off.
Bizarre. Deleting the text entry in the localization tables and retyping it fixed it.
This warning is pretty annoying. Mainly because no matter how many times you disable Normal and Tangent channels they always get turned back on automatically.
Opinions on the UI?
has anyone encountered (at least on mac os) that setting a custom mouse cursor, it reverts back to the OS one when you move the mouse (at least in editor)? The only way I found to keep it from changing back is to put "Cursor.SetCursor(gameCursor, Vector2.zero, CursorMode.Auto);" in the update loop...which is obviously a far from ideal solution.
Why is it that when I add Entry List as the content on my Scroll Rect the whole list gets pushed to the side?
Perhaps show the inspector for the list. Could be your alignment
Or it could be padding if you are using a layout group
I currently have a canvas rendering everything including a camera and some ui elements, I want to add another camera renderin on top of the current canvas in a 300x300 pixel size, how could I do this. When I add a new canvas I cant change the size when it is in screen space rather than world space. I dont have a lot of knowledge so anything would help
Render the camera to a render texture and draw it on the canvas with the RawImage component
But when I do that I cant make it into a corner of the screen since it does not let me control the canvas size
The canvas is not the thing you would be resizing
The object with the RawImage is
why when i build does my UI get messed up?
Because you haven't properly laid out and anchored your UI elements
Take 2 minutes to read this: https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/UIBasicLayout.html
alr ty
dont have your gameview set to 'free aspect' when working with UI
alr
thanks
Anyone know why my TMP text is outrageously blurry from afar?
Third screenshot is the built-in Liberation Sans font asset for reference
Where's the inspector screenshot I asked for ;p
Oh crap sorry didn't see that part lmao
I'm assuming this is what you wanted and not the font asset
Yes, this is the inspector
Now, with the UI version of TMP, it does not like the scale or the font size to be < 1. Your font size is 0.37. I assume the issue happens on the 3d TMP as well, but I haven't used it in years to be able to say for sure
Make your font 1 (or higher), decrease the width/ height of the rect
Or maybe, increase the width/ height of the rect, and the font.. give it an empty parent and lower the scale of the empty parent
That sounds better I'll try that quick
Unfortunately that didn't work
I think it's a bit better? Definitely a tad less smudged from the bloom
But not as clear as liberation sans (none of the fonts I've tried were as clear is though)
Yours looks bold, the lib sans isn't
Is the 'bd' in the font name for bold?
get 'good timing' regular
That didn't even occur to me tbh I just snagged this off dafont
I'll see if I can find it
Doesn't look like there is a regular version I'll try a thinner font though and see if that helps
I don't think it's because of the font. I just tried a thinner font and it's still not as clear
Waaait
When you first created the sdf font asset, did you change any settings?
I've pretty much never needed to edit them
I did not
I just tried adjusting the padding with the thinner font and I think it's clearer than the thicker font I'll do a quick comparison
Okay yeah nevermind it definitely is the thick font
Which sucks because a thick font is really what I need
there's still the bold option on the TMP component, which might work
as in, might look ok
Yeah I'm probably just gonna have to settle for that lol..
Well I appreciate your help thank you
Unity's UI will drive me crazy one day.
Is there really no way to do render layers within a canvas, that doesn't include adding more canvases?
I want one object to be underneath another object, but I can't do it by reordering them in the hierarchy
why can't you reorder the hierarchy?
hierarchy order is the way UI is ordered
there's no other way other than multiple canvases
What are you trying to achieve?
Hey, a question about TextMeshPro. It imports into the Assets folder. Is it 100% safe to move it to another folder (for example assets/plugins? Or could this break functionality/give errors/warnings?
yes, it's safe
I have 2 UI objects, Content, and Background. Background uses this little script
Bounds targetBounds = RectTransformUtility.CalculateRelativeRectTransformBounds(
(RectTransform)rectTransform.parent,
target
);
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
rectTransform.pivot = new Vector2(0.5f, 0.5f);
rectTransform.anchoredPosition = targetBounds.center;
rectTransform.sizeDelta = (Vector2)targetBounds.size + sizeBuffer;
``` to nicely get behind all the children of content, and cover all of them, with a padding of SizeBuffer
now, of COURSE, I have a situation where I want a child of target to NOT be included in this check
is there a reason you're not using layout groups and content size fitters?
probably this
content size fitters are too limiting, and what I'm doing is not really covered by layout groups
Unity's UI system is patheticly limited in that regard, sadly, and I have like 5 helper scripts that adjust sizes of elements on the fly - getting them to work without outright crashing unity in certain situations was a pain
anyway, I have that element that I don't want to include as a child of background instead, as my current workaround, but it should render UNDERNEATH the background
I want it to stick out from underneath the background kinda outside
and I can do it, with careful anchor and pivot setting
but I'm also sometimes scaling the content, and the background updates nicely, but the element that's sticking out scales towards a different anchor point
and I'm afraid that I have to make another helper script, to force its anchor to be the same as content
if you're breaking the rules of normal UI layout, then you will need to do a bunch of extra work yourself, yes
what effect are you trying to create in particular?
not "make an element stick out" -- what kind of interface are you going for here?
I'm using an animation where my content goes between scale of 0 and 1
and the background scales automatically and nicely to account for that
but the decoration underneath the background scales towards the pivot of the background which is set as different than the pivot of the content
the first thing that comes to mind is doing an inverted mask
Id have a parent container and scale that
but I don't think that's supported out of the box
the next thing that comes to mind is this setup:
- Window
- Decoration
- Background
- Button
I think that's what Carwash is suggesting
Decoration would be excluded from auto-layout
(that's an option on the Layout Element component)
very painfully, it is not, I might have to find a good asset or implement it myself because it's been a pain many times
content is within safepadding while background is not, but I suppose that with my current architecture I can get it within safepadding, which would allow this approach, I'll try that
i want to make a nametag above players, but im not sure how.
ive tried attatching the canvas to the player and then:
- rotate the text to the camera
- set the rotation to the inverse of the camera
however both of these barely dont get what i want and im not sure how to fix.
the first one rotates the text on the Y axis which i dont want, i want it to be flat not turned
the second one makes it rotated downwards
that's a z axis rotation not a y axis rotation
anyway you'd have to show your code
oh mb
it should pretty much be text.rotation = Quaternion.LookRotation(-cameraForward, cameraUp);
oh that works, thank you
im giving my script 2 images but when i starting the game remove them
before
after
note that this will make the text look away from you as you turn the camera
which can be a bit weird
(i saw this in a VRChat world recently, which is why it was on my mind)
Ideally, it should look in the camera.position - transform.position direction
Does the rendered color change at all as you change the vertex color?
yeahg but apparently it was the classic "the 'fuck everything up' option is enabled by default" ( color space in project settings was linear, when changing it to gamma fixes this )
I don't know if it's related to UI. But in my game view, I can see the UI texure
Hey! I’m having a weird issue—it looks like a Unity bug, to be honest, but I might be wrong.
I’ve written a script to make the UI Image mask work the other way around (negative stencil):
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
public class CutoffMaskUI : Image
{
public override Material materialForRendering
{
get
{
Material material = new Material(base.materialForRendering);
material.SetInt("_StencilComp", (int)CompareFunction.NotEqual);
return material;
}
}
}
This works great, but only when I start the scene from the Unity Editor. The game runs, and the mask behaves as expected. However, if I start from an other scene and change scenes ( to the one with the mask ) using LoadScene(), the object with the mask is not rendered at all even tho I can see it in the hierarchy (enabled), and if I toggle it on and off, it appears as expected again.
Anyone have a clue ?
I don't immediately have an answer that will fix your problem per se - but I do want to point out this code is very likely to cause a memory leak.
- You're never destroying the new materials you're creating.
- You're creating a new one every single time that property is called, which, I have no idea how many times the engine will call it.
Actually, you gave me an immediate answer—ahah! I fixed the code based on your points, and it seems to be working as expected now. Thank you very much!
Hello, my custom mesh canvas renderer only works when it is behind images and it disappears when it is in front of images, any idea why?
good lord why does that look so similar to the above screenshots
I thought the same, ahah
Well, I guess I am giving up on fixing this, I read through the API and related posts on forums and I just can't find why it gets culled. Whatever I can still use it just it has to be at the back.
maybe a bounds issue?
what bounds is your Renderer outputting?
It is a Canvas Renderer, it does not have a bounds property.
all renderers have a bounds property afaik
indeed - interesting that CanvasRenderer does not derive from Renderer
that's surprising to me
Maybe related to the RectClipping stuff then?
ive been messing with this for a while, im kinda new to unity so i dont know much.
i wanna have a in between screen where player see their point gains from last round, right now i am deleting tmp_texts based on the amount of players there are (delete 1 if there are 5 players, etc)
my issue has been this:
is there a way to make these space evenly? i put them in a layout group but then it just removes from the right
already tried, sadly there is very little info about this component, having it in the back is good enough for me though
- instead of deleting some number why not just instantiate the correct number from a prefab?
- Yes use a layout group. The side it "deletes from" will be based on the where you put the anchor/pivot of the lyout group iirc
basically you just didn't set up your layout group properly
to the first one, i did think of that option but i figured the result would be the same so i just picked one
to the second one, do you mean something in the component? ive messed with all those values. or do you mean the rect transform anchors
to the first one, i did think of that option but i figured the result would be the same so i just picked one
Not really - because with this way you have you need to have the objects in the scene and there is a hardcoded max number of them. You will also be loading these objects into memory just to delete them. It seems... backwards.
For the second thing - the anchors are part of the RectTransform
alr, ill check that out
that is fair, ill change it
Anyway it's quite easy to test the layout group at edit time
just adding/deleting objects
no need to run the game
so - play with things there till it's working properly
i got it to work, thanks :)
I bet that Unity was expecting to get the same material every time it accessed materialForRendering
Yes exactly! I've "cached it" so it works now, I can share the code for anyone that might be interested:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
public class CutoffMaskUI : Image
{
// Cached material instance.
private Material _cachedMaterial;
public override Material materialForRendering
{
get
{
if (_cachedMaterial == null)
{
_cachedMaterial = new Material(base.materialForRendering);
_cachedMaterial.SetInt("_StencilComp", (int)CompareFunction.NotEqual);
}
return _cachedMaterial;
}
}
protected override void OnDestroy()
{
if (_cachedMaterial != null)
{
DestroyImmediate(_cachedMaterial);
}
base.OnDestroy();
}
}
We're updating our project from 2021.3 to 6000.0 and we've noticed something weird, on .32 fonts seem fine but when we moved to .36/.38 it seems like some TextMeshPro font assets are somehow broken and take random characters from LiberationSans default font, despite it not even being in the fallback list. Did anybody ever see something like this? It feels like a bug to us
I have finished the worst part of the game, so now I have a UI working properly with no bugs, but it's ugly. I am not good at ui-ux, so could you give me some advice to improve my ui's beauty?
(The squares of the shop are supposed to be illustrative images about the item)
Look at others and learn from their design choices. Find a style you like and go from there
I didn't know the existence of that website. I will check it out, thanks!
Why is my button text so fucked up? It's skinny and I needed to add a space between every letter
and I can't see any new things I add to the UI.
Fuck I hate UI
Did you scale it non uniformly?
I don't know what you mean
and I can't add any new stuff to the UI, it doesn't show up in game mode
ok I figured out the showing up part but the text is still blurry and skinny
you have probably not placed it correctly then
to properly work on UI do this:
- Set your scene view to 2D mode (2D button on the toolbar)
- Select the Rect tool
- double click your canvas in the hierarchy
yeah solved that part
it's already in 2d mode and textbox is about the size of the button
you'd have to show the inspectors of those objects
for new text added, it's not showing up at all
again ^
screenshots
why are the height and width so tiny
1 and 2 pixels?
you're doing something weird here
Can you show your whole canvas?
And jus8t share full screenshots of the whole editor, don't crop it
Also would recommmend not using the legacy text
scaled my parent object to 60, 60 without provocation
yeah I know tmp is better but I need the bare basics for this
using the rect tool
unity doesn't change the scale of anything without you telling it to do so
Does anyone know why my buttons click area is so offset, I tried remaking the buttons and moving them from the container into just the canvas but it still happens?
Look at their RectTransforms with the Rect Tool in scene view
Looks like this, the only difference between buttons is the pos X
I mean visually look at their gizmos
Oh, they look ok I think?
Use the Rect tool
Not the move tool
And why is there a green outline 🤔 did you add a physics collider to it?
Oh wow, it was the text box attached to the button... The width was too big
This is all that's in it, I thought it was just the bounding area
Hi, what texture resolutions do people tend to author for UI on desktop? I assume 4K and just let Unity downscale on lower resolutions? I'm about to create a ton of UI, but not really done this in earnest and just want to get it right from the start... but there's like a million articles about supporting multiple resolutions all with their own tips and tricks. So curious if there is a right way?
Use a comfortable resolution for your dev machine as your reference resolution and then test the final result across the popular targets
I tend to use 1920x1080 as the reference resolution
Yeah, that's what I've been doing, but I'd like the textures to look good at 4K too. So was going to export 4K based textures but still use 1080p reference for the canvas. Just not sure how well Unity downscales and if there's things that can be done to keep the textures looking good at common resolutions - 1080p, 1200p, 1440p etc. since only 1080p is perfectly divisible into 2160p
The reference resolution doesn't have anything to do with image resolution or downscaling really in the final product
It's for layout purposes
Yeah, I'm more interested in the actual texture resolutions of the sprites. I assume everyone just designs their art for the best res (4k?). Import them at those sizes and let unity downscale them for users at lower resolutions.
any good recommendations of ui code architecture? I'm mostly finding some really basic "how to create a button" or very specific things or some very very custom things. Haven't done UI in Unity before and tbh in general I find all ui (not just Unity) inherently messy outside some immediate mode debug stuff :D
Trying to come up with some generic solution for interactable ui elements, since it feels like ui code "wants" to fall into a spiderweb chaos where delegates and dependencies are flying all over the place. I'm thinking of something like state machine for interactable ui elements. Like OnClick etc. would invoke a delegate with next button state as return value. Somewhat limiting as we can only invoke one single function at a time, since multiple return values would mess it up.
As a more concrete example: enum InteractableState with values Enabled, Disabled, SuccessEnabled, SuccessDisabled, Failure. Player presses "Buy Food" button and delegate is invoked. There is enough money, enough food and more food to buy, so SuccessEnabled is returned. Button state machine goes to SuccessEnabled state, some effect is displayed and sound played and after that button goes back to Enabled state.
don't design your game (code) as ui first, make gameplay systems first, then create views into those systems. Make a 'presenter' that deals exclusively with routing input from a view into these systems and displaying their state. Make your system APIs totally UI agnostic.
typically you'll be well advised to make a state-machine that controls all the primary game states and potentially all the individual UI panels. If you keep them modal (only one panel at a time), you can a void a lot of spaghetti
well I do already have many gameplay systems in place and currently mostly manipulating things with debug booleans on inspector and tbh it feels like UI agnostic API would just mean super complex ui configuration, as in UI system or some middleman between UI and gameplay would have to be aware of all kinds of gameplay system specific information, as opposed to gameplay system just telling ui "I'm out, please disable yourself"
well, its possible that your whole game is structured in a way that making a non-complicated UI is impossible.
yeah I've also considered that possibility after finding reddit posts and stuff where people complain that tycoon game code they inherited is absolute mess :D
maybe the boundaries between systems haven't been drawn in useful places or you haven't layered & sliced your systems and everything is just a pot of ravioli.
but regardless, UI is always complicated and feels like a waste of time
This is not a tycoon game per se, but has some similarities as in has resource management and both global and local UI elements will have many different states, which depend of gameplay system values
i find that even the most elegant gameplay systems ages into a shrivelled pig when it receives UI, metrics tracking, notifications, logging and localization
... and then you google ui architectures, both game- and non-game related, and everyone is just talking about super simple "here is a button and it interacts with this event system or interface and everything is super agnostic" and I'm like... fuck it I have like five buttons that simple here :D
something i've found useful in tycoon games is to make the primary game design concepts into UI-panels and just isolating that view as best possible from the rest of the code. I.e. make a complicated presenter if you have to, just try to not pollute the systems that implement the game logic with it.
there is no such thing as a generic ui architecture, at best these would be stuff like MVVM or Component-Based or React-like, lower level maybe immediate, retained, forms-like etc.
hmm, now that actually sounds pretty good idea
separate the mess into a closet and close the door
yes
at least that creates a nice boundary and you can see what goes in/out in one place
@proud sandal thanks, this feels indeed much better, even if it's somewhat anomality in my general code structure, but it's better to contain the anomalities into specific places
I tend to lump that under minimalist
To clarify I’ll have total hundreds of interactive ui elements in the end and maybe five of them fall into fire and forget category
Does anyone know how to get these images to stop becoming ovals, ive set them as these. Im trying to make it into just a standard health bar / meter but its keeping turning ovally lol
If i have it set to tiled, it goes back to normal
you probably have some weird scaling or something.
these r my scales, its fine when i set it to tiled but i need it to be filled cause its a health bar system
that's the sacle for the health bar
what about its parent objects?
And what kind of canvas is it living on?
ive set up the UI_Canvas but havent changed much in it
I believe ive figured it out now
and the image is a direct child of this? Or there are other objects in between?