• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Konsicrafter · Aug 27, 2016 at 06:55 AM · c#error messagescript errornamespace

The type or namespace "UnityEngine" could not be found - Can not edit scripts

Hello, I have a problem, in Visual studio there is an error in the first line "using UnityEngine;", which says: "The type or namespace UnityEngine could not be found. I have no idea what to do, I asked google for hours and did not find a solution. I reinstalled Unity, I reinstalled Visual Studio Community. This error is only occuring in some projects, some other projects work fine. I can temporarily fix the error by clicking "project->Add reference" and then searching "Unity" and ticking everything in the list, but as soon as I open another script or open VisualStudio I have to do it again. Thank you in advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by villevli · Aug 27, 2016 at 07:32 AM

You can regenerate the Visual Studio project files by deleting the .csproj and .sln files from your Unity project folder. Open any script in your project through the Unity Editor and Unity will recreate the files. You can also use Assets - Open C# Project.

If your issue is not fixed, look in the folder Library\UnityAssemblies in your project directory. The Unity libraries including UnityEngine.dll should be there. If not then you can copy them from another project's folder. You can also try to delete the whole Library folder when the project is not open and let Unity regenerate it. (May take some time depending on your imported assets) (Don't do this if your project is created in Unity 4.2 or earlier. reference)

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Konsicrafter · Aug 27, 2016 at 09:41 AM 0
Share

Thank you for your answer, but it did not fix it. The files are being recreated but the error still occurs.

avatar image Bunny83 Konsicrafter · Aug 27, 2016 at 09:53 AM 0
Share

Are you sure that you actually open the solution and not just a single script file? Without the .csproj file open you will miss all assembly references. Also do you have installed right version with the Visual Studio Tools for Unity? It usually comes with the Unity installer.

The visual studio tool are necessary so you can directly open a file from the editor.

avatar image Konsicrafter Bunny83 · Aug 27, 2016 at 10:30 AM 0
Share

Thanks for your answer. I tried exactly this, but it did not work. I have the right and latest version of VS Tools installed. I have the project opened aswell, not a single file. I just found out, when I delete all .csproj and sln-files the xxx.Assembly.csproj-files are not regenerated,

Show more comments
avatar image villevli · Aug 27, 2016 at 11:17 AM 0
Share

Look in the folder Library\UnityAssemblies in your project directory. The Unity libraries including UnityEngine.dll should be there. If not then you can copy them from another project's folder. You can also try to delete the whole Library folder when the project is not open and let Unity regenerate it. ($$anonymous$$ay take some time depending on your imported assets) (Don't do this if your project is created in Unity 4.2 or earlier. reference)

avatar image Konsicrafter villevli · Aug 27, 2016 at 11:32 AM 0
Share

It worked! Thank you! I did not have the UnityEngine.dll file, I deleted the Library directory and after 1 $$anonymous$$inute of compilation it's finally working!

Solution: If you don't have UnityEngine.dll in the Library directory of your project just delete the Library directory (while unity is closed). After this open Unity.

avatar image
4

Answer by ExNinja · Aug 15, 2019 at 07:01 PM

In Unity 2019.2.0f1, deleting the Library folder does not fix the problem. For me, this problem arose when I tried running the 2019.3.0a11 alpha. Uninstalling and reinstalling Unity 2019.2.0f1 did not help.

However, deleting the Visual Studio Community (macOS) app from the Applications folder and then reinstalling it via Unity Hub did work.

  1. Delete the Visual Studio application from the Applications folder (I have the CleanMyMac app, and it managed the uninstall process for me, but I think that just deleting the app would work too).

  2. In Unity Hub, click the Installs button on the left.

  3. Click the three vertical dots in the top-right corner of any installed version of Unity and choose Add Modules.

  4. Select the Visual Studio module at the top and install it.

That worked for me. :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Errors with Unity Advertising after redownloading project and reenabling ads 0 Answers

Multiple Cars not working 1 Answer

Accessing Java class from C# script 1 Answer

Script only works onetime 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges