Search Unity

[Solved] Camera issue with the UI - pixel perfect (shaking)

Discussion in 'Scripting' started by DouchesOfTheCoast, Aug 29, 2021.

  1. DouchesOfTheCoast

    DouchesOfTheCoast

    Joined:
    Nov 1, 2020
    Posts:
    9
    Hi, my programmer in my team is having a problem with the UI when it follow the player (main camera). When it switch or initiate a new scene, it "shakes".

    Any help is welcome, he has been days trying to fix it.

    I uploaded a video with english subtitles (he doesn´t speak english), that you need to turn on.







    And here is the problem itself.


    Pixel Pefect Component that is added to the camera when the scene is loaded

    upload_2021-8-29_18-44-21.png

    In late update, the fragments of code that moves the camera and the interface shown in the youtube video

    upload_2021-8-29_18-44-26.png

    Already tried:

    1- Put it in FixedUpdate()

    2- Make the interface son of the camera

    3- I checked with two inspector windows if when I move the player, the position of the camera in relation with the interface differs even in a decimal... but no, they are equal (the same).
     

    Attached Files:

    Ptolomeo likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Do you need to have the panel viewed by the camera? You can make it a ScreenSpace Overlay and it will not move at all when the camera moves.

    If you need it as Camera space, you could also make another camera ONLY for the UI using Layers.

    Also, consider this timing diagram, and perhaps by stepping through your code you can reason about where the computation is not quite correct:

    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html
     
    Jamisco and Ptolomeo like this.
  3. DouchesOfTheCoast

    DouchesOfTheCoast

    Joined:
    Nov 1, 2020
    Posts:
    9


    It seems the readjustment of the camera with the physic pixels of the pixel perfect system don't work directly with the canvas. So I needed to ask from script the component "CameraPixelPerfect", and send to it the canvas position and then return me the correct position with the function "RoundToPixel()".

    I hope this help others with a similar problem.
     
    Last edited: Sep 2, 2021
  4. Carlos_7x

    Carlos_7x

    Joined:
    Jan 19, 2017
    Posts:
    16
    Did this solve your issue? sorry for the bump but I'm facing this issue and I'm trying to fix it like this:

    Code (CSharp):
    1.     public PixelPerfectCamera ppc;
    2.  
    3.     private void LateUpdate()
    4.     {
    5.         transform.position = ppc.RoundToPixel(transform.position);
    6.     }
    With no success. Thanks.