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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Cinemachine Issues & how to force position update

Discussion in 'Cinemachine' started by khold93, Mar 8, 2022.

  1. khold93

    khold93

    Joined:
    Feb 11, 2020
    Posts:
    17
    Unity Version: 2020.3.23f1

    1. My Cinemachine has stopped updating position in editor. It will only update when I click "Solo" or deactivate/activate Camera GameObject. It will only update once.

    Edit:
    It updates in editor if I switch from FixedUpdate to Smart Update in Update Method (CInemachine Brain). Not sure if that is intended or not?

    2. I have not been able to force position update on start/awake. It won't update before game has started, and its easy to see that the camera is at position A before it Jumps to position B. Same issue if I click (R) to reload level.
    Have also tried ForcePos, OnTargetObjectWarped, disable/enable camera & tested about every setting in the inspector.
    Only solution have been to create a "Start" camera that has a static position & placed on the correct position, then transition over to "Normal". This is mainly a issue because my levels reset quite often, and then my camera will have this minor "teleport/jump" that looks pretty bad. With a static camera on start pos, it won't have that jump. Not the best solution, so if anyone have a suggestion or how I can force position update before player can see it - please share :)

    3. Sometimes I have seen that virtual Cameras that are on standby will get "Field of view" instead of Orthographic Size. It will update correctly if I click solo or start the game, but it swaps back and forth between FoV & Ortho in Editor. Is this normal?

    https://imgur.com/a/bTlld72 All the camera settings

    StateDrivenCamera


    Main Camera


    Normal Camera

     
    Last edited: Mar 8, 2022
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,321
    Unity doesn't run FixedUpdate in editor mode, which explains why the vcams aren't updating since you have it set to update in FixedUpdate.

    If you need them to update in edit mode, maybe you write a little script to set your CMBrain to update in LateUpdate while in Edit mode, then switch to FixedUpdate when it enters Play mode.

    I don't really understand your question #2, unfortunately. Can you elaborate?

    Question #3: sometimes it happens, but it's harmless. What version of CM are you using? You can see in the Package Manager.
     
  3. khold93

    khold93

    Joined:
    Feb 11, 2020
    Posts:
    17
    Thanks for the information.

    I will implement it if needed. Smart Update seems fine for now, can't recall why I changed it in the first place. Haven't touched the camera in a while.

    Using CInemachine 2.6.11. Cheers for confirming that it is harmless

    Small update so you are caught up:
    I only have "Normal" and "Dead" CinemachineVirtualCamera now.
    2D Game - small level

    My player is moved to start position when the game enters playmode (void Start())
    I want the "Normal" Camera to instantly change to the same position as the player.
    Currently the player is moved first, and then the camera is moved.

    The problem is that you can see 0.1 sec of the original camera position, before camera's position is updated.
    I have to reload scene when player dies, so it will happen quite often.

    I have tried:
    Updating camera position with ForcePosition/transform.position in Start() (with & without follow/look at)
    Tried using vcam.OnTargetObjectWarped(target, delta), but nothing happens so I'm not sure if I use it correctly.
    (delta = newPosition - oldPosition)

    A couple solutions:
    1. In the editor: Move camera manually to start position without follow/look
    2. In the editor: Move the player object to the start position, because camera follows player in the editor
    However none of these are ideal for testing purposes

    Thanks for replying Gregoryl. I see your name in every Cinemachine thread, true mvp.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,321
    Thanks for the details.

    The vcams update in LateUdate or FixedUpdate, depending on your setting. Since this is after Start, they should immediately snap to the correct position if you're just entering playmode. There is no reason for them to be elsewhere. Are you sure that you don't have another vcam active somewhere? Is there some complexity in your object creation code that might be interfering? If the player is being instanced later in the frame, its Start will be called synchronously.

    Can you repro this problem in a test project?
     
  5. khold93

    khold93

    Joined:
    Feb 11, 2020
    Posts:
    17
    Took a second look and I can't find any other vcams. If I disable those I find I won't get a display.
    Player Object is always in the scene. No complexity in object creation.

    Creating a new Project now, will take a bit of time before its all setup
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,321
    Maybe you can show your hierarchy. I'd like to see the relationship between main camera, vcam, and player.
     
  7. khold93

    khold93

    Joined:
    Feb 11, 2020
    Posts:
    17
    When I was creating the Test Project, I discovered that Blend Update Method was Late Update by default.
    That reminded me that I changed it way back because of how background objects followed the camera.. so switched camera Blend Update Method back to Late Update and it's fine now,
    My bad. Didn't think Late Update vs Fixed would matter in this case.

    Just have to figure a better way to make objects follow the camera instead.

    Not that interesting anymore I guess, but incase you want to see.



    Thanks a lot for taking time to help me.
     
    Last edited: Mar 8, 2022
    Gregoryl likes this.
  8. maikkanerva

    maikkanerva

    Joined:
    Dec 14, 2018
    Posts:
    26
    Hi, I am having similar issues but not on start/awake.

    I have a virtual camera, that is following a point that is a child of a player object.
    My situation is that I have an arena, where the player can fall off, and if they do their position is reset to a specified position. Currently my CM Brain is using Smart Update, and for blending Late Update.

    The issue is that whenever the position is reset, the camera follows from beneath & through the map geometry to the reset point, instead of snapping to the camera distance + offset position that is normally has. The position is reset through an OnTriggerEnter, so I asumme that happens on FixedUpdate. I have a C# event that is invoked whenever this happens.

    I've tried to use the virtualCamera.ForceCameraPosition(position, rotation), but this has absolutely no effect on the camera position, the camera just keeps following smoothly.

    I've tried:
    1. Just using the ForceCameraPosition when the event is invoked
    2. Waiting for the end of the frame to reset the position
    3. Toggling a flag, that enables position reset on LateUpdate.


    upload_2022-5-2_15-39-3.png
     
    Last edited: May 3, 2022
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,321
    Have you tried setting vcam.PreviousStateIsValid = false at the same time as when you reset the target's position?
     
    zelderus and Kondziu2504 like this.
  10. maikkanerva

    maikkanerva

    Joined:
    Dec 14, 2018
    Posts:
    26
    Hi! Sorry for the late reply.

    Yes I tried that now, but it didn't solve the issue.
    I tried setting that flag false before the follow transform is moved, and also after it, but it had to effect.

    UPDATE:

    Actually got it working now.
    I was using the ForceCameraPosition method, but instead all I had to do is to set the PreviousStateIsValid to false, and actually just set the transform.position of the virtual camera.
     
    Last edited: Jun 22, 2022
    ATate, zelderus and Gregoryl like this.