Search Unity

Trouble with vcams, works in editor but broken in mobile builds

Discussion in 'Cinemachine' started by mbeierling, Jan 22, 2019.

  1. mbeierling

    mbeierling

    Joined:
    Jan 8, 2019
    Posts:
    4
    We use Cinemachine's Freelook setup to orbit an object, and have interaction points that we want to focus on click. We achieve this by having 2 virtual cameras, that we spawn in the Awake() lifecycle method:

    Code (CSharp):
    1. // Spawn VCam
    2.     this.vcams = new List<CinemachineVirtualCamera>(new CinemachineVirtualCamera[]{
    3.       new GameObject("VCam 1").AddComponent<CinemachineVirtualCamera>(),
    4.       new GameObject("VCam 2").AddComponent<CinemachineVirtualCamera>()
    5.     });
    6.     this.vcams.ForEach(v => v.gameObject.SetActive(false));
    On click of an interaction point, we set the LookAt and the position of the vcam. The position is calculated based on a spawn object, which is located at the center of the object. The interaction points are all at the hull of the object.

    Code (CSharp):
    1. activeVcam.gameObject.SetActive(false);
    2.     var vcam = nextVcam();
    3.     vcam.m_LookAt = interactionPoint.transform;
    4.     vcam.m_Priority = 10;
    5.     vcam.gameObject.transform.position =
    6.       interactionPoint.transform.position +
    7.         Vector3.Normalize(
    8.           interactionPoint.transform.position - spawnObject.transform.position) * 2f;
    9.      
    10.      vcam.gameObject.SetActive(true);
    11.  
    This all works fine in Editor, with a nice transition between the FreeLook cam rig and the vcam looking at the interaction point.

    In the mobile (e.g. Android & iOS) build, it moves to the location of the interaction point and looks always straight into the Z direction (0,0,1).

    What's really weird is the discrepancy between editor & mobile.

    Any ideas what could cause this?

    An alternative approach would be to spawn a VCam in the beginning for each of the interaction points, which should work fine as we don't reposition anything. This behaviour is still weird enough that I thought I'd post it here.
     
  2. mbeierling

    mbeierling

    Joined:
    Jan 8, 2019
    Posts:
    4
    Same problem happens in the above described alternative approach, where we spawn a VCam for each interaction point.

    I'm starting to think that the positioning code behaves different on mobile and in editor...
     
  3. mbeierling

    mbeierling

    Joined:
    Jan 8, 2019
    Posts:
    4
    After reading the tooltip of m_LookAt, which says
    "The object that the camera wants to look at (the Aim target). If this is null, then the vcam's Transform orientation will define the camera's orientation."

    I added the following code to the end of the vcam spawning loop:

    Code (CSharp):
    1. vcam.transform.LookAt(pointInstance.transform);
    And now the vcams are correctly orientated. So it appears that the m_LookAt ref is empty in the mobile build.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    I'm suspicious of this line:
    Code (CSharp):
    1. vcam.m_LookAt = interactionPoint.transform;
    On the mobile, does interaction point continue to exist after the vcam is spawned? Can you add some debugging to prove that it doesn't get deleted?
     
  5. mbeierling

    mbeierling

    Joined:
    Jan 8, 2019
    Posts:
    4
    I'm very sure that the interaction point objects still exist, as they have a renderer attached which is visible on mobile.

    Also, the vcams for each interaction point get spawned in the same loop the interaction points themselves are spawned. So even if the points get re-created, the vcams should also get recreated.

    I will add some debugging and make sure of it though.
     
  6. jacobhouston_unity

    jacobhouston_unity

    Joined:
    Mar 5, 2018
    Posts:
    6
    Hey did you ever find a solution to this? My 2D cinemachine cameras work fine in the editor, but seem to revert to (0,0,0) in the build. This happens to all cameras that transition/crossfade via the inbuilt unity timeline.

    Was working a few months ago last build test.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Sorry for the delay - I was on vacation.
    Can you upload a small demo project that shows this problem?
     
  8. jacobhouston_unity

    jacobhouston_unity

    Joined:
    Mar 5, 2018
    Posts:
    6
    Hi @Gregoryl, thanks for the reply. Here's a link to a small demo project. In the editor, the VCAM starts looking at the fallen column, then pans to my character, zooms in, zooms out. In the build however, the camera starts zoomed in to the character. This is a constant theme throughout my project, the final camera movement is where it starts - so I amend my previous comment, it doesn't seem to be reverting to (0,0,0).

    I've updated to CineMachine 2.3.4, but that didn't fix it. It seems like it happened after updating Unity... Anyway, here's the file. https://mega.nz/#!xmh2BYqA!t_az_yeDtr5yHwzbQ4KKR7Hz4e0PKfu6N9d4f8xwt5Y

    Thanks again.
     
    Last edited: Sep 17, 2019
  9. nikitadezhic_unity

    nikitadezhic_unity

    Joined:
    Mar 17, 2020
    Posts:
    7
    It helped me to create a prefab virtual camera with Aim mode "Composer" (the default is "Hard Look At"). Maybe just changing the Aim mode is enough, but I haven't figured out the way to do it in runtime.