Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. 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 at 8:51 AM.

  1. Tycellent

    Tycellent

    Joined:
    Nov 7, 2014
    Posts:
    3
    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:
    3
    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,408
    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:
    3
    I see. Thanks for the reply!