Cant find Unity Cinemachine virtual camera reference even though it is referenced in the inspector. (and when referenced through script is doesnt work

I made a script to switch through two different camera’s for locking onto an enemy (My logic isn’t finished yet but not the point).
I first had a public variable called CinemachineVirtualCamera and referenced my gameobject with the CineMachine virtualCamera to that variable.
But it gives me this error:

Severity Code Description Project File Line Suppression State Warning CS8032 An instance of analyzer Unity.Properties.SourceGenerator.PropertyBagGenerator cannot be created from C:Program FilesUnityHubEditor2022.3.25f1EditorDataToolsUnity.SourceGeneratorsUnity.Properties.SourceGenerator.dll: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Het systeem kan het opgegeven bestand niet vinden.. Assembly-CSharp C:Program FilesUnityHubEditor2022.3.25f1EditorDataToolsUnity.SourceGeneratorsUnity.Properties.SourceGenerator.dll 1 Active

but the script does exactly what I tell it to do.

But when I referenced the variable through the start method with getcomponentinchildren<CinemachinVirtualCamera>() I didnt get the error but the script didnt do what I wanted it to do

should I just ignore the warning or am I doing something wrong?

This is my whole script:

[Header("Bools")]
public bool locked;

[Header("Lock on settings")]
public LayerMask enemyLayer;
public float radius;
public float maxAngle;

//private void Start()
//{
//    enemyCamera = GetComponentInChildren<CinemachineVirtualCamera>();
//}
public void Update()
{
    Inputs();
    PlayerLookAt();
}

void Inputs()
{
    if (Input.GetKeyDown(KeyCode.Mouse1) && !locked)
    {
        if (enemyCamera == null)
        {
            print("Waarom werk jij niet");
        }
        enemy = CalcEnemyLock();
        enemyCamera.LookAt = enemy;
        SetCamera();
    }
    else if (Input.GetKeyDown(KeyCode.Mouse1)  && locked) 
    {
        locked = false;
        SetCamera();
    }
}
Transform CalcEnemyLock()
{
    Collider[] nearbyEnemy = Physics.OverlapSphere(transform.position, radius, enemyLayer);
    float closestAngle = maxAngle;
    Transform closestTarget = null;

    if(nearbyEnemy.Length <= 0)
    {
        return null;
    }

    for(int i = 0; i < nearbyEnemy.Length; i++)
    {
        Vector3 dir = nearbyEnemy[i].transform.position - mainCamera.transform.position;
        dir.y = 0;

        float angle = Vector3.Angle(mainCamera.transform.forward, dir);
        if (angle < maxAngle)
        {
            closestTarget = nearbyEnemy[i].transform;
            closestAngle = angle;
        }
    }
    locked = true;
    return closestTarget;
}
void SetCamera()
{
    if (locked)
    {
        freeLook.Priority = 10;
        enemyCamera.Priority = 20;
    }
    else
    {
        freeLook.Priority = 20;
        enemyCamera.Priority = 10;
    }
}
void PlayerLookAt()
{
    if (locked)
    {
        player.LookAt(enemy);
    }
    else
    {
        player.LookAt(null);
    }
    
}

I tried referencing it in different ways so the cinemachinevirtual camera variable wouldnt be null but the script only worked when it was null

New contributor

Can Silay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật