Microsoft.Unity.Analyzers/doc/UNT0014.md

26 строки
765 B
Markdown

# UNT0014 GetComponent called with non-Component or non-Interface Type
`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
```csharp
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.