Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Changing the path position on a tracked dolly through code

Discussion in 'Cinemachine' started by spelafort, Feb 7, 2020.

  1. spelafort

    spelafort

    Joined:
    May 8, 2017
    Posts:
    29
    Hi,

    Seems like this should be really easy, but I've been having a ton of errors. Cinemachine namespace repeatedly gets lost and I need to reinstall from packman, but this means even after I've fixed it I'm not sure if it's my code or some other problem.

    The situation: I'm just trying to manually lerp a virtual camera on a path using code. But I keep getting nullreference exceptions, despite triple checking that it's finding the right object. Even when I remove the lerp code it throws the same error:

    Code (CSharp):
    1. tmpDolly.gameObject.GetComponent<CinemachineTrackedDolly>().m_PathPosition = 1f;
    The object is a virtual camera with the CinemachineVirtualCamera component. Shouldn't this code be finding the object that has a Cinemachine virtual camera (and the proper body settings)? Or am I missing something about how these components work?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    Yeah the CM components are a little tricky. You have to first get the CinemachineVirtualCamera component, and then ask it for the required Cinemachine component. Something like
    Code (CSharp):
    1. tmpDolly.GetComponent<CinemachineVirtualCamra().GetCinemachineComponent<CinemachineTrackedDolly>().m_PathPosition
    I don't know why you keep losing the CM namespace. Do you have an asmdef in your project that you need to add it to?
     
  3. spelafort

    spelafort

    Joined:
    May 8, 2017
    Posts:
    29
    Whoa, I had no idea that second getcomponent was a thing. Thank you!

    As for the other thing, not as far as I know. I recently migrated this project from my laptop to my desktop this is when it began... hoping it will keep the namespace reference as this most recent reinstall :)

    thank you!
     
  4. spelafort

    spelafort

    Joined:
    May 8, 2017
    Posts:
    29
    whoops, nope: just restarted the project and it lost the namespace again. That was fast. Any other ideas what this could be? using Unity 2019.3.0f6 and VScode.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    Usually that sort of thing is an asmdef lurking somewhere in your project.
    Have you tried re-importing?
     
  6. spelafort

    spelafort

    Joined:
    May 8, 2017
    Posts:
    29
    Reimported overnight, and it worked for a moment (even the actual script worked! It panned!) but it's toast again.

    It seems to work with visual studio instead of VScode, so it may require migrating..

    EDIT-- no, it's actually broken on studio as well :(
     
    Last edited: Feb 7, 2020
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    What version of Visual Studio are you using? I have VS 2019 and it works perfectly.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,485
    It's possible that you are tripping over a known issue with the VS integration, relating to csproj files for packages not being reliably generated. The VS integration team tells me that there is a PR in flight for this, and when that is done it will be released as soon as possible. So hopefully within a couple of weeks you can upgrade to 1.1.5 and have things working.
     
  9. spelafort

    spelafort

    Joined:
    May 8, 2017
    Posts:
    29
    Hi, switching to VS2019 fixed the issue. Would love to go back to VSCode, however!

    Anyway thanks for your help, will keep my eyes open for the fix.
     
unityunity