• 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
Question by ryanbailey · Aug 12, 2013 at 07:24 PM · transformpositionbug

Position variable not updating

Hey everyone! I have recently noticed a very strange issue with the transform.position setter. When setting this in a LateUpdate function I have noticed immediately after setting a value it is not the desired value. Below is a small code snippet.

 LateUpdate() {
 
     transform.localScale = new Vector3(0f, 0f, 1f);
 
     transform.position = new Vector3(0f, 0f, 0f);
 
     if (transform.position.x != 0) {
         Debug.LogError("No change at X position: "+transform.position.x);
     }
 }

In this snippet, the debug statement somehow get called. Does anyone have any idea why this may be occurring?

Comment

People who like this

0 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 Jerdak · Aug 12, 2013 at 07:28 PM 0
Share

Directly comparing floats isn't a good idea. Instead do something like if( |a-b| < someReallySmallValue). floating point representations can be slightly off.

avatar image Joyrider · Aug 12, 2013 at 07:36 PM 0
Share

I've tried your code snippet on Unity 4.2.0f4, and works all right on my end; no error being logged.

avatar image ryanbailey · Aug 13, 2013 at 04:17 PM 0
Share

I forgot to mention that it is the child of a child of an object that is moving around and being scaled. I am adjusting values based on the new scale and then setting its position back to 0.

I believe it has to do with what Jerdak says, when the object is scaled inside another object the floating point precision can be off.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by IgorAherne · Aug 13, 2013 at 12:02 AM

Make sure external scripts don't change this value. Check for subtle errors. For example == and = might be playing a trick on you, and instead of comparing the variables, you change them, etc

Comment

People who like this

0 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 idiot333 · Feb 26, 2015 at 04:52 PM 0
Share

My lookAt function is not working because transform.position doesn't update. :(

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

parent Transform.position unexpected behaviour when changing position 1 Answer

Why does moving a game object transform work in the WebGL build but not the Windows build? 1 Answer

transform.position = new Vector 3 NOT moving to correct position? 1 Answer

got char stuck near objects. 1 Answer

Issues with local position and positions 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