Search Unity

Can't access Cinemachine via c#

Discussion in 'Cinemachine' started by grossimatte, Apr 7, 2018.

  1. grossimatte

    grossimatte

    Joined:
    Mar 15, 2013
    Posts:
    43
    Hello,
    as per title, i am trying to access the cinemachine virtual camera script parameters via a custom c#.

    There is no mention on how to do that on cinemachine documentation.

    Any idea?

    Thanks!
     
  2. grossimatte

    grossimatte

    Joined:
    Mar 15, 2013
    Posts:
    43
    Edit:

    I figured it out.

    - add
    using.Cinemachine
    on top of the script.
    - refer to the cinemachine camera using
    public CinemachineVirtualCamera vcam
    ;

    you can now access all the parameters:
    upload_2018-4-8_0-8-9.png

    Remember the cinemachine virtual camera might update on a different Update method ("Smart", fixed, late), so make sure to add all your per-frame calculations in the right one, or you won't get the behaviour you expect. (you can check and specify the update method used by the virtual camera clicking on the virtual camera gameobject).

    Hope this will help.
     

    Attached Files:

  3. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
  4. grossimatte

    grossimatte

    Joined:
    Mar 15, 2013
    Posts:
    43
  5. Chregu

    Chregu

    Joined:
    Jan 7, 2018
    Posts:
    3
    Hi everyone
    I have a problem that visual studio won't find the Cinemachine Namespace (CS0246) eventhough I installed cinemachine into my project... it once worked but now it won't find the namespace anymore.
    Funnily enough on the unity side of things everything works normally, meaning that if i ignore the errors it works correctly in unity.

    Any ideas why this is happening?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Try updating your Visual Studio Tools for Unity
     
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I've encountered same issue, but for Jetbrains Rider. Is there something that can be done?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Can you log a bug report with a repro project? It would be much easier to track down that way. Right now it's a little vague.
     
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    There's not much really to repro. I'm using Unity 2018.1.7f1 for that project. I've simply installed the Cinemachine via the package manager.

    It works as intended in Unity (there's no errors), but ReSharper in Rider doesn't pick anything from the Cinemachine package, stating that it is not found, highlighting everything related as errors.

    Tried restarting both IDE's, no luck, so I've reverted to Asset Store version.

    Which works just fine. Also, I've installed Text Mesh Pro via Package Manager, and it is picked by the Rider as well.

    Edit: Just realized that I've hijacked the thread, since OP was asking about completely different question. My original post was related to this one:
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    ok, but the folks in charge of solution generation (not me) would like a bug report, so that the issue gets tracked and addressed efficiently. The likelihood of the bug getting fixed tends to be directly proportional to the specificity of the report and the reliability of the repro steps.
    Just saying :)
     
    xVergilx likes this.
  11. jin-chen

    jin-chen

    Joined:
    Sep 15, 2014
    Posts:
    4
    Good day guys, I'm using Unity 2018.2.9f1, and still can't access in code cinemachines API, even if I'm using the namespace, I was downloading the asset through the package manager, and reimporting and also updating the project, still nothing happens and the code editor keeps showing and error meanwhile implementing "using Cinemachine". If any of you guys got this fixed please please, share it :D

    Have a nice day you all.
     
  12. jin-chen

    jin-chen

    Joined:
    Sep 15, 2014
    Posts:
    4
    By the way installing the asset through asset store works perfectly :cool:
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    1. Make sure your Visual Studio is upgraded, to get the latest Unity Tools for VS
    2. If you have a local .asmdef in your project, you'll need to add a dependency on com.unity.cinemachine
     
    SenneDB likes this.
  14. FoxProject

    FoxProject

    Joined:
    Aug 30, 2015
    Posts:
    2
    I quit Visual Studio and opened it again and then I could use the Cinemachine namespace
     
    Lazyfella likes this.
  15. Krblshna

    Krblshna

    Joined:
    Oct 7, 2017
    Posts:
    2
    you are awesone guys, finnaly I can control cinemachine props via script, thanks!
     
    nuxmakesgames likes this.
  16. Rsl081

    Rsl081

    Joined:
    Jun 10, 2020
    Posts:
    3
    Nice one guyss, help me a lot thankyou!
     
  17. sidchou

    sidchou

    Joined:
    Apr 13, 2020
    Posts:
    12
    I have the same problem, and my vscode dont even recognize the name space
    the code run fine, just odd that its not recognizing
     
  18. SilverynArdryll

    SilverynArdryll

    Joined:
    Apr 2, 2022
    Posts:
    1
    do we have any solution for it, I have the same issue too
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Same issue as what? Code runs fine but VS not recognizing? Sometimes a restart of VS and/or Unity does the job.
     
  20. terencelee1234

    terencelee1234

    Joined:
    Nov 23, 2021
    Posts:
    2
    upload_2023-1-7_20-12-23.png
    I solved the VSCode issue by clicking the regenerate project files button, hope this method also can solve that on your side.
     
    Rinaf and Troy457 like this.
  21. Troy457

    Troy457

    Joined:
    Nov 26, 2022
    Posts:
    1
    Solved it for me aswell. Cheers mate!
     
  22. Siamenau

    Siamenau

    Joined:
    May 26, 2016
    Posts:
    2
    write on the top:

    using Cinemachine;

    and for example:

    camera.GetComponent<CinemachineFreeLook>().Follow = newPlayer.transform;
    camera.GetComponent<CinemachineFreeLook>().LookAt = newPlayer.transform;
     
  23. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    I'm having the same issue
    even if I follow all answers fund on forum.
    Using unity 2021.3.8f1
    Visual Studio Editor Package 2.0.18
    Cinemachine 2.8.9

    It works perfectly as long as I don't want to code anything related to it.
    Screen2023-06-17 07 44 35.png
     
  24. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
  25. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    I solved The problem By Creating an Assembly Definition Which will reference Cinemachine and Other Libraries Used
    Screen2023-06-17 08 21 50.png
    Screen2023-06-17 08 21 29.png

    Hope this Helps
     
    xinyic_ likes this.