Search Unity

Issue with Unity and Visual Studio Interactions

Discussion in 'Editor & General Support' started by Agrian, May 28, 2019.

  1. Agrian

    Agrian

    Joined:
    May 17, 2019
    Posts:
    6
    New User here, sorry if this is a known issue, but my Google searching has not produced any answers or insights a novice like me can use/interpret so here I am asking for help.

    I am going through some lessons as a new user and ran into an issue where I realized my Visual Studio's IntelliSense functionality is not working. I have made sure the Unity expansion is down loaded and installed and I have tested the issue on both 2017 and 2019 for Visual Studio, as well with Unity 2019.3.0a2 and 2019.2.0b3 and the issue persists with any combination of Unity and Visual Studio.

    I have attempted to use the option in preferences to set the default editor to Visual Studio however this creates a new issue where I can not open the script files in Unity at all. Opening them externally also still has the lack of functioning ItelliSense.

    I have a few screen shots of things I believe to be related to the issue, though it is a pure guess on my part. My reasoning is based mostly on looking at my lesson plan videos, screen shots, and other tutorials and looking for discrepancies in the interface and screen text.

    The first image show two items circled in red in Unity and Visual Studio that I know are connected to the issue. One is the red circle on the left and that area being populated as Misc File, it should as I understand be the project name, which should also be mimicked at the top of Visual Studio though I could be wrong there. The right circle is some notification that there's a failed import of monobehavior stuff which as I understand it is key to the intellisnse working.


    This image is to show that I have tried toggling the External Script Editor and not resolved the issue on 2017 or 19 but I know where it is at least. Also to show I have the script named and created where it should be. I also circled these two errors popping up in the console. Both seem related to missing files but I again lack enough knowledge to make use of the information.


    Any help on this would be really appreciated as I am more or less locked up on this and can't really go forward until I sort it out.
     
  2. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    The names of the class and script file must match. In your case you have a NewBehaviourScript class in Player.cs
     
  3. Agrian

    Agrian

    Joined:
    May 17, 2019
    Posts:
    6
    In the photo it apparently does not match as you point out. Though I am unsure why. I followed the steps and used Create -> C# Script and named it. As I (and possibly incorrectly) understand it when I generate and name the script that should set it automatically or use the rename option correct?
     
  4. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @Agrian You're correct, that should have worked. Did you create the C# file from the Unity Editor or from Visual Studio? Try creating it from the Unity Editor if you didn't already.

    With the alpha of 2019, there is a new package used for the integration with Visual Studio. Make sure it's updated by checking in the Package Manager in Unity. If it is, and you still have issues, I'd report a bug for that package.
     
  5. Agrian

    Agrian

    Joined:
    May 17, 2019
    Posts:
    6
    I was able to duplicate the problem with both the 2019 alpha build and the previous version, also with Visual Studio 2017 and 19 Community. So I am working off the assumption there is something going wrong either at install or in the set up steps, what few there are. The fact that the files generated inside Unity when opened in Visual don't have the right name/source(?) in the upper left as I circled in image 1 I think is telling, as is the lack of Intellisense in Visual Studio, and that if I set Visual Studio to the specified external editor I can no longer open code.

    I am very new at this and not a software person by trade. But my arm chair thought is that there is some kind of communication/file propagation issue happening between the two. And if that is the case I have no idea what to do about it. Though to be fair I have little idea of what to do about the issue on any level. It is extremely daunting and frustrating as some one trying to just engage the learning process.
     
  6. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @Agrian Another thought: If you created the file in the Unity Editor and hit enter, it would create it with the name NewBehaviourScript.cs. From there, if you highlight it again or chose Rename to rename it, it will only rename the file and not the actual class definition inside the code. This would cause the two to be out of sync. You can easily fix this by deleting the file and trying again - making sure to name the file before you press Enter in the Unity Editor after creating it.

    If you have code in this file already that you'd like to keep, you can rename the class inside Visual Studio by right-clicking on the class name and choosing Rename.

    I just tried VS 2019 and the latest Unity 2019 Alpha and things are acting strange. Go to the Window > Package Manage in Unity and find the Visual Studio Editor and Visual Studio Code Editor packages that are in the project. Update them both to the latest versions. That fixed the opening of files, but it's still not 100%. We'll report the issue here.
     
  7. Agrian

    Agrian

    Joined:
    May 17, 2019
    Posts:
    6
    I will nuke the lesson project, wasn't able to get far enough for it to be any real loss. I will unistall Unity and my VS. I will find a clean install of 2017 and validate I have the Unity packages for it to try and hedge out any 2019 weirdness and do a clean install of Unity with the previous version of 2019 b I think it is? And see if I am still getting the issues after that. It will be after 7:30 pm CST before I'll have a chance to report in if it solves the issue or if it persists. Part of me wishes some one had the time to do a Discord voice chat so I could stream my desk top and make sure I'm not just being a complete idiot on this.
     
  8. Agrian

    Agrian

    Joined:
    May 17, 2019
    Posts:
    6
    Issue seems to be resolved atm. Going to poke at it a bit more to be sure. But it looks like rolling back to Visual Studio 2017 and Unity 2019.1.4f1 has solved the issue for now. So the issue is in the interaction with the current Unity a/b and Visual Studio 2019. Beyond that I have no idea the details.
     
  9. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,475
    same here. vs2019, unity new version, can't open script from unity.