简体   繁体   中英

Unity project builds successfully, but VS Code throws The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine'

I have similar projects which don't exhibit the issue, but this one does. It specifically can't resolve UnityEngine.EventSystems in my class, despite the fact that it can resolve using UnityEngine.

My Unity version is 2020.3.13f1.

I believe the package in question is Unity UI which resolves to com.unity.ugui and is referenced in my project under both UnityEngine.UI.csproj and UnityEditor.UI.csproj.

Unity can clearly see the package and rebuilds dynamically in response to changing the code base, but VS code can't, despite it having no issues seeing other Unity packages. It doesn't seem to be a caching issue from what I can tell.

using UnityEngine; <- can be resolved
using UnityEngine.EventSystems; <-- can't be resolved

public class TestScript : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, 
IPointerUpHandler, IPointerExitHandler
{
    public void OnPointerEnter(PointerEventData eventData) { }
    public void OnPointerDown(PointerEventData eventData) { }
    public void OnPointerUp(PointerEventData eventData) { }
    public void OnPointerExit(PointerEventData eventData) { }}
}

Any hints would be most appreciated:-)

Suggestions:

Check these two 'embedded packages' and 'local packages' boolean inside your unity under:

Edit/Preferences/ExternalTools

and click on 'Regenerate project files' and it will work.

Actual Problem: its happening because VS Code is specially slow and some times it doesn't even detects the some packages/namespaces in unity specially because of the unity extensions installed in VS Code (its not problem to have them because ofcourse they are necessary to work with unity and for intellisense but that extension is usually slow in VS Code so...), and it usually doesn't happen if you use any full IDE like VS community or Jetbrains Rider, they seem to be handling this issue by them selves you don't need to worry about it.

Note: I know that the author of this question has already answered him self in the comments but for the people who might be wondering about it I thought I just put it here in answer for them so they can find solution easily and also to clarify why actually this problem happens in the first place.

Hopefully it helped... Happy coding:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM