- Home /
Faulty 'unused' errors in vscode for `Update` and `Start`?
I'm using vscode for scripts in unity. I have code completion setup which is nice.
One issue however is that I'm getting faulty warnings in vscode: Private member 'EnumExample.Start' is unused. [Assembly-CSharp] csharp(IDE0051) [10, 10]
I get this type of error for every Update
and Start
and any other fn that end up being called by the Unity Engine.
So, how do we get rid of this faulty 'warnings'? I don't want to turn of the unused function warning. What I want is for vscode to know that it does get called so it does not issues the warning.
Can I see your code? It's kinda hard for people to help when they don't know the code.
Answer by Aquinos135 · Feb 09, 2021 at 11:53 PM
I believe this is a similar question to this discussion
In which case the fix is within Unity, you go to Edit=>Preferences=>External Tools, and click on Regenerate project files. This should refresh Unity's configuration with Visual Studio and allow it to see that Start() and Update() are actually used by the engine.
From the looks of that specific error, you may have also made your Start() method private, which it shouldn't be, the declaration should simply be void Start() {}
From the looks of that specific error, you may have also made your Start() method private, which it shouldn't be, the declaration should simply be void Start() {}
This is misleading. Omitting the access modifier does default to private. So private is always optional. It makes no difference. All members always have an access level and the default one is private.
Note: to avoid this issue you may want to use protected on the Unity callbacks. Especially when you may want to use inheritance it's always a good idea to use protected as a hidden method in a base class won't be called by Unity because Unity uses reflection to call the callbacks on the actual class.
Answer by SkillcraftHD · Jul 15, 2021 at 01:39 PM
Found a fix: Go To Your Project folder and delete the file with the ".sIn" extension. This will be regenerated by Unity automatically and restart the connection with Visual Studio. Visual Studio needs to be reopened by a C# File in Unity as normal.
Answer by TaxiDave · Aug 12, 2020 at 09:22 AM
I got the warning too out of nowhere.
But only for some of the script files and for other functions like OnCollisionEnter too.