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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug Cinemachine orbital freelook unable to aim at animated body in build only

Discussion in 'Cinemachine' started by infinitejess, Oct 12, 2023.

  1. infinitejess

    infinitejess

    Joined:
    Jan 29, 2019
    Posts:
    4
    Hi, I can't share a whole lot in the way of video and most of my configuration is coded, but I'm hitting an issue with cinemachine and I can't find any solution online or through tinkering, was hoping someone might have some wisdom.

    I've built a cam system for a game that uses an orbital freelook for most of the movement states. There's a primary freelook camera uses the scroll wheel to raise/lower the orbit heights and radii to zoom in and out, with a PoV trigger when you zoom all the way in. There's also vcams that inherit from my third person freelook script with variations for crouching, climbing, swimming, etc. All the vcams live in a CameraConductor game object with a class that uses my movement state machine to blend between them.

    The aim target is set when a camera is turned on to look at the animated body (RatModel in the pic) of the player, which is a child of the Player object with a kinematic rigidbody with interpolation on. So everything happens in Late Update and the cinemachine brain is set accordingly.

    This works great in play mode (aside from some persistent jitter bugs I've researched endlessly with no solution but that's for a different post). The bug arises when I build. I've built to mac windows and linux and it's present in all three. Basically, once I start the build, my aim target gets extremely confused and points about a meter behind the player. It's almost as if the y axis offset is at like -10 or something (it's not -- currently set to 2.5 to point at the player's head). In addition to that, the input isn't working right: the movements of my mouse correspond to camera controls in a way I don't even know how to explain, like the orbit splines are confused about the input axes. But long story short, the aim target is off, and the orbits are not the size/shape I expect, and the input doesn't navigate them how I would expect.

    The bug completely disappears when I change the aim target to be the outer player object with the rigidbody. Unfortunately this makes the camera jitter noticeably worse and doesn't work with root motion animations as the camera needs to follow the animated body for certain animations like climbing a ledge. I might try to script a transition camera that changes out the aim target during root motion animations, but this feels like a hack, and leaves me with camera jitter.

    I know this is tough to debug without video explanation but I don't have permission from the art department to share anything. I can share a pic of my cinemachine config but it's pretty dead simple, a lot of the complexity is in the code. Some of my values are set at runtime so if anything looks empty when it shouldn't be that's probably why. So while I try to reproduce the bug in a smaller project, are there any obvious hiccups where an aim target might have different behavior in a build vs. play mode? Anything about pointing at an animated body, or child of a rigidbody that might explain it? Maybe something about the script load order? Been at it for a few days with no progress, not sure what else to try.

    Thanks in advance, sorry for the wall of text
    AimBugAimConfig.png AimBugCinemachineConfig.png AImBugHierarchy.png
     
    Last edited: Oct 12, 2023
  2. infinitejess

    infinitejess

    Joined:
    Jan 29, 2019
    Posts:
    4
    Oh, I'm using Unity 2022.3.4f1 and cinemachine 2.9.7
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    Everything looks fine in your setup. CM has no knows issues re. build vs editor. It's very likely that the problem is in your code, and given that you are mentioning jitter issues and rigidbodies it might have to do with update vs fixedUpdate or script ordering.

    Since you can't share any visuals from the project, my advice to you is to put some effort into extracting your camera and player controller logic into a separate project and reproducing the issue using simple objects (cubes, capsules, etc). Then you can share that project and we can help you find the problem.
     
  4. infinitejess

    infinitejess

    Joined:
    Jan 29, 2019
    Posts:
    4
    Thanks for the reply! It's a lot of interconnected code so I'll do my best. I can probably share my camera code easily but I'll need to figure out how to mock out our animation controller namespace.

    Would a zipped unity project directory work for you?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    Yes that would be fine. You can DM it to me if you like. Delete the Library directory first, it's huge and Unity can regenerate it.