You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using GetComponent doesn't give any indication of what your script actually needs in the Unity Editor. That's one of the reasons I prefer serialized fields, but GetComponent still has its uses.
Proposed solution
If this.GetComponent is used anywhere in a MonoBehaviour script, offer a code "fix" to add a [RequireComponent] attribute to that class.
I wouldn't want a blue underline for it though since the script could simply null check the component and ignore it if not present. Maybe the analyser could detect that it isn't being null checked?
The text was updated successfully, but these errors were encountered:
Very Interesting idea. It might be hard to prove that the component is actually required or not, but that's something we could offer as a suggestion which is not very intrusive.
Problem statement
Using
GetComponent
doesn't give any indication of what your script actually needs in the Unity Editor. That's one of the reasons I prefer serialized fields, butGetComponent
still has its uses.Proposed solution
If
this.GetComponent
is used anywhere in aMonoBehaviour
script, offer a code "fix" to add a[RequireComponent]
attribute to that class.I wouldn't want a blue underline for it though since the script could simply null check the component and ignore it if not present. Maybe the analyser could detect that it isn't being null checked?
The text was updated successfully, but these errors were encountered: