Unity doesn't seem to be recognising classes in my scripts.

I may be wrong about the cause of the problem but in Visual Studio I get errors for all my classes which are inside the base class (the one that inherits MonoBehaviour). For example, in the script BulletBehaviour, for the Start class I get the error “IDE0051: Private member 'BulletBehaviour.Start; is unused”. I’ve only just noticed now that I’ve tried to write the code

private void OnCollisionEnter(Collision collision)
    {
        Destroy(gameObject);
    }

Instead of destroying on collision, the bullets are destroyed almost instantly upon being fired. I assume it has to do with the above error but I’m not sure, if anyone knows a solution please let me know. Thank you in advance :).

This is probably just a warning, not an error, otherwise you wouldn’t be able to enter play-mode at all. Which is just you being told about something that doesn’t stop your code from compiling, but should probably fix. Ergo, if your Start method is empty, you should remove it.

It is completely unrelated to your current issue. Which is likely because your bullets are being spawned touching your gun, most likely, and thus immediately destroying themselves. Usually this kind of systems will check what they’re actually hitting first before destroying themselves.

Thanks for the response. The first issue happens to every class regardless of if it has content in it. The second issue, I’ve realised the bullets are destroying each other when they spawn because it’s automatic fire lol, thanks.

Check that you correctly linked Unity with your IDE.
Edit → Preferences → External Tools → External Script Editor

Edit:
As for your second issue, check that they actually collide with something other than a bullet, or use collision layers

1 Like

In addition to check if Visual Studio is set as the correct editor, make sure your Visual Studio installation has the Unity Tools extensions installed as well. From a pure technical point of view, private members inside a class that aren’t used anywhere inside that class would create such a warning since the compiler thinks in normal OOP rules and knows that nobody can actually access that member. However Unity calls those magic methods from the native side and can actually invoke private members. AFAIK when the Unity Tools are installed in VS, the IDE shouldn’t show those warnings.

So in Visual Studio go to Extra → Tools and features. This should bring up the Visual Studio installer. Check if the “Workload” “Game development with Unity” is installed. If not, do that :slight_smile: Not sure how that workload is called exactly in english. However you should be able to find it.

2 Likes

I remember Visual Studio doing that ALL the time. Warning: Update() is unused. Every script. Is that still the case even in VS 2022? Like … if this still happens to this day, Microsoft severely doesn’t give any craps whatsoever about us boys playing with toys.

This is just one out of 2,490,856 issues that made me never look back after switching to Rider. :wink:

To be fair, a private method with no callers is invalid/mistaken/useless/unreachable code in C#. It’s only because Unity does everything with weird reflection hacks for the “magical” message methods that this is an issue. Making the Update() public would probably make the warning go away.

1 Like