Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug VirtualCamera.LookAt working in editor but NOT in runtime

Discussion in 'Cinemachine' started by moorhuhnhd, Apr 22, 2021.

  1. moorhuhnhd

    moorhuhnhd

    Joined:
    May 23, 2019
    Posts:
    5
    I created a virtual camera that looks at a gameobject called "Target".

    Everything is working fine while in editor. The target is always in the center of the screen.

    But once I build the project and run it, the camera position (or is it rotation? basically where it looks at) is stuck in the starting position.

    This seems like a bug to me or maybe a case I didn't consider.

    If you need specific code or examples I can both show you my code as well as upload footage.
    (I didn't so far because I really have no idea what could be the problem here.)

    EDIT: I don't know if it helps, but the camera is using a dolly track. (so it's moving all the time, hence the look at).
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    It's difficult to say with this information. :)
    Let's try with a photo of your hierarchy, photo of the inspector for your vcams and main camera. Maybe we can see something from that.
     
  3. moorhuhnhd

    moorhuhnhd

    Joined:
    May 23, 2019
    Posts:
    5
    Hierarchy:
    Hierachy.png

    VirtualCamera:
    VirtualCamera.png

    MainCamera:
    MainCamera.png

    Thanks in advance. :)
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I think, you just need to set a Follow target for Tracked Dolly. ;)

    In general:
    Position of the camera is determined by Body, and Body uses Follow target to calculate the position.
    Rotation of the camera is determined by Aim, and Aim uses Look At target to calculate the rotation.
     
  5. moorhuhnhd

    moorhuhnhd

    Joined:
    May 23, 2019
    Posts:
    5
    Unfortunately, this doesn't solve the problem. :(
    It still works in the editor but not in runtime.

    What are possible differences between both environments? It feels like part of the script isn't executed properly.

    EDIT:
    I checked the rotation of the main camera and the vcam as well as lookAt and Follow in both environments. LookAt and Follow are pointing to target (as they should) but in the runtime build the rotation of neither the main camera nor the vcam changes.

    EDIT2:
    I recorded the exact same camera movement in both environments:


    I honestly don't know what to look for since it's working in the editor... It's quite hard to debug as well. :)
     
    Last edited: Apr 23, 2021
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Can you send me your project? I'll look at it. You can send me a direct private message.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,141
    Why do you have a SimpleCameraController on the main cam? What is it supposed to do? Maybe it's fighting with the CM Brain. Try disabling it.
     
  8. moorhuhnhd

    moorhuhnhd

    Joined:
    May 23, 2019
    Posts:
    5
    Basically I want to be able to move around in the world (using the SimpleCameraController) and set waypoints, which are later used to create a tracked dolly path.

    Every functionality of the SCC is skipped once a track is created.

    What bothers me a lot is the fact that it does work in the editor game view but not after building it.
    Should I just try disabling this and that in the blue or is there an actual way of debugging the runtime?
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,141
    You should try disabling it just to see if the problem is related to it.
     
  10. moorhuhnhd

    moorhuhnhd

    Joined:
    May 23, 2019
    Posts:
    5
    Although I still don't completely understand the issue and why it worked in the editor but not in runtime I managed to fix it:
    Instead of a HardLockToTarget
    Code (CSharp):
    1. CinemachineHardLockToTarget aim = vcam.AddCinemachineComponent<CinemachineHardLockToTarget>();
    I had to use a HardLookAt.
    Code (CSharp):
    1. CinemachineHardLookAt look = vcam.AddCinemachineComponent<CinemachineHardLookAt>();
    2.  
    Does make sense. ^^

    Thanks for the help and your time!