Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Setting Confiner Programmatically

Discussion in 'Cinemachine' started by Tycellent, Aug 13, 2018.

  1. Tycellent

    Tycellent

    Joined:
    Nov 7, 2014
    Posts:
    14
    Hey everyone,

    I'm currently trying to access and set the confiner for a CinemachineVirtualCamera programatically. However, i'm not quite sure how to access the Confiner of the camera programatically. I was thinking it'd be something along the lines of...

    Code (CSharp):
    1. CinemachineConfiner lCinemachineConfiner = lMyCinemachineVirtualCamera.GetCinemachineComponent<CinemachineConfiner>();
    and with that assigned i was hoping i could access its properties via something like this:

    Code (CSharp):
    1. lMyCinemachineVirtualCamera.m_ConfineMode = CinemachineConfiner.Mode.Confine2D;
    2. lMyCinemachineVirtualCamera.m_BoundingShape2D = m_SceneConfider;
    3. lMyCinemachineVirtualCamera.m_ConfineScreenEdges = true;
    It seems that i'm not retrieving the CinemachineConfiner correctly and i guess i was hoping to get some help with this.

    Any help will be appreciated and thank you to anyone visiting this!
     
  2. aDev_

    aDev_

    Joined:
    Jan 23, 2018
    Posts:
    6
    Hello,

    m_ConfineMode, m_BoundingShape2D & m_ConfineScreenEdges are properties of the confiner. So your code should be something like this:

    Code (CSharp):
    1. CinemachineConfiner lCinemachineConfiner = lMyCinemachineVirtualCamera.GetComponent<CinemachineConfiner>();
    2.  
    3. if(!lCinemachineConfiner)
    4. {
    5.             lCinemachineConfiner = lMyCinemachineVirtualCamera.AddComponent<CinemachineConfiner>();
    6. }
    7.  
    8. lCinemachineConfiner.m_ConfineMode = CinemachineConfiner.Mode.Confine2D;
    9. lCinemachineConfiner.m_BoundingShape2D = m_SceneConfider;
    10. lCinemachineConfiner.m_ConfineScreenEdges = true;
    11.  
     
    Tycellent and Gregoryl like this.
  3. Tycellent

    Tycellent

    Joined:
    Nov 7, 2014
    Posts:
    14
    Ahh yeah you're right works perfectly. Thanks!

    Bit off topic but when should i be using .GetCinemachineComponent<>()? i was under the impression that .GetCinemachineComponent<>() should be used whenever we want to get a property from the Cinemachine Virtual Camera component
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
    You use that one only for the Aim/Body/Noise sub-components that don't have inspectors of their own. Everything else is an ordinary component.
     
    Tycellent likes this.
  5. Tycellent

    Tycellent

    Joined:
    Nov 7, 2014
    Posts:
    14
    I see. Thanks for the reply!