UNT0014 GetComponent called with non-Component or non-Interface Type
January 12, 2022 ยท View on GitHub
GetComponent, TryGetComponent, GetComponents, GetComponentInChildren, GetComponentsInChildren, GetComponentInParent, and GetComponentsInParent should be called only with Types that extend UnityEngine.Component, or Types that are an Interface
Examples of patterns that are flagged by this analyzer
using System.Collections;
using UnityEngine;
class Camera : MonoBehaviour
{
private int i;
private void Start()
{
i = GetComponent<int>();
}
}
Solution
Make sure the type argument passed to any GetComponent method extends UnityEngine.Component, or is an Interface Type.
No automatic code fix is available for this diagnostic.