Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

UGUI UI lagging behind camera movement

Discussion in 'Cinemachine' started by capitalJmedia, Apr 21, 2018.

  1. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Hi I've recently added Cinemachine cameras to my game but I'm getting a big lag between the UI positions and the camera position. Ie: in this video the ui should be attached to the tanks but as I move the camera around the UI lags behind in a jelly look.

    I have my cinemachine brain set to LateUpdate (but I've tried Smart Update as well). The UI is a Screen Space - Overlay canvas.

     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,946
    This is a known issue in Edit mode, but if it's happening in Play mode then there's something wrong.
    Does this happen in Play mode as well as in Edit mode?
     
  3. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Yes, it happens in play mode. The above gif is from play mode.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,946
    Can you export me a small package that demonstrates this?
    Also: which versions Unity and CM?
     
  5. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    I'm using 2017.4.1f1 and cinemachine 2.1.10

    not sure if I can export some sort of package from the game, it would take quite a while to put something together and we are releasing next week.. But here's a script I use to anchor the UI to a gameobject, perhaps this cant be done on lateupdate with cinemachine?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AnchorUiToObject : MonoBehaviour {
    5.  
    6.     public Vector2 offset;
    7.     public Transform objectToFollow;
    8.     public bool followCurrentSelectedObject = false;
    9.  
    10.     private RectTransform uiElement;
    11.     private Camera mainCamera;
    12.  
    13.     // Use this for initialization
    14.     void Start ()
    15.     {
    16.         if (PlatformSettings.Instance.isVR)
    17.             mainCamera = GameObject.Find("Camera (eye)").GetComponent<Camera>();
    18.         else
    19.             mainCamera = GameObject.Find("MainCamera").GetComponent<Camera>();
    20.  
    21.         uiElement = GetComponent<RectTransform>();
    22.     }
    23.  
    24.     public void SetObjectToFollow(Transform followThis)
    25.     {
    26.         objectToFollow = followThis;
    27.     }
    28.  
    29.     void Update()
    30.     {
    31.         if (followCurrentSelectedObject) {
    32.             if (BattleManager.Instance.currentSelectedObject != null)
    33.             {
    34.                 objectToFollow = BattleManager.Instance.currentSelectedObject.transform;
    35.             }
    36.         }
    37.     }
    38.  
    39.     // Update is called once per frame
    40.     void LateUpdate ()
    41.     {
    42.         if (objectToFollow)
    43.         {
    44.             if (!PlatformSettings.Instance.isVR)
    45.                 uiElement.position = RectTransformUtility.WorldToScreenPoint (mainCamera, objectToFollow.position) + offset;
    46.         }
    47.     }
    48.  
    49. }
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,946
    ah! In that case your problem is most likely in Script Execution Order. Edit that and put
    AnchorUiToObject after CinemachineBrain.

    upload_2018-4-23_14-47-15.png
     
    howong likes this.
  7. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Yes, that was it, thank you!
     
    howong and Gregoryl like this.
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,946
    @abedathman8 was this post a mistake? It seems incomplete, and I don't really think it belongs in this thread...
     
  9. howong

    howong

    Joined:
    Oct 9, 2017
    Posts:
    6
    Oh my gosh, I was having troubles with making UI objects always face the camera and setting the lower priority (higher number) in Script Execution Order seemed to fix the issue even with or without Cinemachine. Thanks Gregoryl!