Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend [RequireComponent] when using GetComponent on self #35

Open
SilentSin opened this issue Feb 26, 2020 · 2 comments
Open

Recommend [RequireComponent] when using GetComponent on self #35

SilentSin opened this issue Feb 26, 2020 · 2 comments
Labels
help wanted Issues identified as good community contribution opportunities

Comments

@SilentSin
Copy link
Contributor

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, 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?

@jbevain
Copy link
Member

jbevain commented Mar 6, 2020

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.

@sailro sailro added the help wanted Issues identified as good community contribution opportunities label Apr 26, 2021
@sailro
Copy link
Member

sailro commented Apr 26, 2021

Automatically adding "help wanted" tag for stale issues identified as good community contribution opportunities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

3 participants