Search Unity

Question Transform position/scale precision problem

Discussion in 'Editor & General Support' started by zIyaGtVm, Mar 30, 2020.

  1. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    I'm sorry, I'm not quite sure what the problem is, or what keywords should I search for answer.
    I have tried many keywords but got nothing.So I post this thread.
    When changing gameObject in Hierarchy, The position/scale will automatically change by a small number like 0.00001 or 0.00002.

    GIF3.gif
    Here is the structure.Target GameObject's scale changed when I move it to another place.
    The parent object has a (0, 90, 0) rotation.
    The more steps the more offset.
    I wonder if it will cause many other potential problem such as walls' z-fight, or different scale prevent batching?
    Any advice would be appreciated.Thanks!
     
    Last edited: Apr 2, 2020
  2. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Anyone knows how to fix this?:(
     
  3. AnKOu

    AnKOu

    Joined:
    Aug 30, 2013
    Posts:
    123
    It is due to the fact that computer can't put in memory infinite floating points value. So there is rounding occuring.

    The only thing to remember is to not compare float value in your script by using == operator (at least after they are altered by arithmetics operation)
    You must use Mathf.Approximately to compare float value. or check with >= or <= depending on your case.
    https://docs.unity3d.com/ScriptReference/Mathf.Approximately.html

    It will not creates problem because rounding occurs at micrometer scale... (given that 1 unit in unity equals 1 meter)
     
    Last edited: Apr 2, 2020
  4. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Thanks AnKOu! Now I know this is a floating-point arithmetic.
    Do you mean the scale difference in editor is so small that it won't break dynamic batching?:)
     
  5. AnKOu

    AnKOu

    Joined:
    Aug 30, 2013
    Posts:
    123
    https://docs.unity3d.com/Manual/DrawCallBatching.html

    It is said that dynamic batching is broken in case of mirror scale so I don't think it is going to be an issue in your case.
    Well, try it and you'll see.