Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by NickCaligo42 · Aug 27, 2016 at 11:09 PM · unity 5uirecttransform

Rect transform position keeps changing value randomly

I've got a row of buttons I'm trying to position manually. I set their rect transform X position to 300 like so: alt text

After I input it, the position changes to something close, but each rect transform is incorrectly positioned by some random floating point value. Here you can see that it's changed itself to 299.2984. Sometimes it'll be off by a value less than 0, sometimes it'll be four or five whole units off, all of its own accord, and it will change every time I try to put a new value into this field.

alt text

I've tried shutting off all the other scripts I've got attached and changing the anchor point to different things, but nothing seems to stop this from happening. Does anybody have any insight on what this is or how to fix it?

positionx.png (208.9 kB)
erroneous.png (234.2 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Aug 27, 2016 at 11:32 PM 1
Share

This is probably due to floating point inaccuracies. Rect transforms are pretty tricky, and some stuff they do it automaticly, based on your settings. $$anonymous$$ake sure to check out https://docs.unity3d.com/$$anonymous$$anual/class-RectTransform.html AND especially https://docs.unity3d.com/$$anonymous$$anual/UIBasicLayout.html

I suspect if you specify the rect transforms differently, like changing anchor settings, or using raw mode, this issue will go away.

avatar image DiegoSLTS · Aug 27, 2016 at 11:53 PM 0
Share

"sometimes it'll be four or five whole units off" <- I've never seen that. If you really have that you should report a bug

The tiny differences, yes, it's pretty common and shouldn't be a problem, they're always too small to make a difference. Also, it's not something you can or should fix, it's something that shouldn't be a problem at all for the game. If 0.0016 difference in x is visible in your game you're probably doing some weird stuff with scales and the canvas scaler, otherwise a 300 and 299.9984 should translate to the exact same pixel in the screen. Also, if you're planning to use that value in code you shouldn't expect exact values working with floats, so again, it shouldn't be a problem if you know how to work with them.

I do get that putting 0 and seeing it turn into something like 2.35e-10 can make it look like it's not working O$$anonymous$$ and can make people obsessed with getting the exact value, but like @Glurth said it's related to how floats and the whole engine works, so you have to accept that it will happen every now and then.

avatar image NickCaligo42 DiegoSLTS · Aug 28, 2016 at 12:10 AM 0
Share

Nope. Glurth was right. Floating point error. The menu it was nested inside of was scaled to an extremely tiny size, less than 0.01. I'm not sure how or why it got scaled to that size, but that caused floating point error in all of its child GameObjects, which looked rather alar$$anonymous$$gly like involuntary random jumps of four or five entire single units in local space.

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by NickCaligo42 · Aug 28, 2016 at 12:05 AM

Figured this out largely thanks to @Glurth's comment. Although it seemed like several entire units was a bit much to be attributed to floating point error, it isn't if your object is nested inside something that's scaled. This was a result of the entire menu being scaled to an extremely tiny size (less than 0.01) in order to fit the camera. After fixing the scale, the rect transform's position values behaved correctly. I'm still not sure what led to the menu getting scaled to begin with, but imagine it had something to do with my noodling with different canvas settings.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by lucasnuke · May 11, 2018 at 09:52 PM

For anyone for whom @NickCaligo42's solution doesn't work: I encountered a similar effect when dealing with a ScrollView->Viewport->Content hierarchy, where the Content position value kept changing when selected or the game run.

The issue had to due with the Viewport anchors being set to stretch and fill the size of the ScrollView, and the Content height specified in game units. I was able to fix it by changing the Viewport anchors so that only the non-scrolling dimension is set to scale to the size of the Scroll View, with the scrolling dimension anchors set to an edge and the width/height specified in game units (probably the same size as your Scroll View).

(Additionally, it seems that the the content must be larger than the viewport).

Example: ScrollView->Viewport->Content

Scroll View has a width and height of 100x200, and you want it to scroll vertically. You have the Viewport anchors set to X-min/max: (0,1), Y min/max: (0,1), and Left/Right/Top/Bottom set to 0. You have Content anchors set to X-min/max: (0,1), Y min/max: (1,1), with a height of 300. Pos Y keeps changing randomly.

To fix, change the Viewport anchors to X-min/max: (0,1), Y min/max: (1,1), and height to your Scroll View height (should be changed automatically).

Hope this helps!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image spicycurrybreath · Jun 02, 2021 at 05:12 AM 0
Share

Came here looking for this exactly, thanks!

avatar image
0

Answer by gabiedc · Aug 02, 2020 at 02:39 PM

I had a very similar issue in Unity 2019.4.2f1, so its still not totally fixed, but for me the solution was making sure that the Content's height was equal or larger than the Scroll View's height. Something about the Content's height being larger causes it to bug out slightly.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

111 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stacked UI Panels do not position as expected 0 Answers

Button rect transform top 0 Answers

Moving RectTransform over another RectTransform under GridLayout 0 Answers

Move a UI element with respect to canvas scaler 0 Answers

Snap UI Text inside canvas 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges