How to change look at target for CineMachine?

So i finally am happy with my cinemachine setup, however… I want to set the target by script, I’ve tried it this way but unsuccessful

    Cinemachine.CinemachineVirtualCamera c_VirtualCam;

    [SerializeField] Transform target;

    private void Awake()
    {
        c_VirtualCam = this.GetComponent<Cinemachine.CinemachineVirtualCamera>();
    }
    private void Start()
    {
        c_VirtualCam.LookAt(target);
    }

EDIT: This worked!!

    Cinemachine.CinemachineVirtualCamera c_VirtualCamera;
    [SerializeField] Transform target;

    private void Awake()
    {
        c_VirtualCamera = GetComponent<Cinemachine.CinemachineVirtualCamera>();
    }
    private void Start()
    {
        c_VirtualCamera.m_LookAt = target.transform;
        c_VirtualCamera.m_Follow = target.transform;
    }
8 Likes

this doesn’t work for me :confused:

NullReferenceException: Object reference not set to an instance of an object

it worked thank you

Did you set your target in the inspector?

Thank you so much.
It is working…:sunglasses::wink:

roses are red, violets are blue, this code is now copyed and pasted.

I hate to be pedantic but copying and pasting code doesn’t always work.

I did it on a project myself last week, it didn’t work.

Also, if you type in the code yourself, watch your spelling/grammar, it’s VERY sensitive.