3

I am developing Unity game apps on a PC using C#, using Visual Studio Code as the editor. The apps are targeted at PC and Android. Multiplayer uses Photon Pun 2.

The Unity version is 2019.3.14F1 - I don't want to move forward just yet in case of 'unexpected problems'.

The VS Code version was 1.48.3 - and everything was fine, no compile errors, all code working OK etc.

Stupidly, I took Microsoft's advice to update VSC, and VS Code went to 1.50.1. Result of this is that there are all sorts of errors showing up in VS Code relating to the Photon code. All these errors stem back to the 'using Photon.Pun;' line. It says "the type or namespace name 'Pun' does not exist in the namespace 'Photon' (are you missing an assembly reference?)".

The code however does not come up with any compile errors in the Unity editor itself, and it all runs fine, including the Photon parts. The problem is in VS Code.

I realise this is almost certainly as VS Code problem, not Photon, but I am wondering if anyone has met this before and knows how to fix it?

(This is why I do not want to move from 2019.3.14F1 to 2020.whatever at the moment - you never know what might happen).

nmw01223
  • 1,611
  • 3
  • 23
  • 40

6 Answers6

3

I had the same problem. Installing different versions of VS Code / VS Community Edition didn't fix anything for me, but this did:

With the project open in VS Code, find all occurrences of

<ReferenceOutputAssembly>false</ReferenceOutputAssembly>

in *.csproj files, and replace them with

<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
4026
  • 51
  • 7
  • Interesting. There are 49 occurrences on 13 files. I haven't tried changing them yet as with 1.48.2 it is all working OK. Those lines / files are automatically written by Unity? I guess I need to find out what they do and what settings - if any - controls the true/false flag. – nmw01223 Nov 09 '20 at 11:40
  • Yep, the `.csproj` files are generated by Unity. You can force regenerate them in Preferences -> External Tools. The entries generated for other libs in those files reference compiled DLLs, while the Photon PUN stuff is just raw code files dumped in your project by the asset store. I assume that's the cause of the issue. I'm not sure why Unity generates the Photon references without `ReferenceOutputAssembly` turned on, though. – 4026 Nov 10 '20 at 09:36
  • I had this problem twice. Your solution worked for me twice. Thanks a lot @4026 – Le Quang Nhan Sep 08 '21 at 02:57
1

Tried rebuilding project files, swapping to a different editor (VS Community Edition 2019 - that was fine), but no difference - VSC persisted with the errors. Rest of intellisense working OK.

In the end, totally uninstalled VSC and reinstalled, and that sorted it out. No idea what the actual fault was.

nmw01223
  • 1,611
  • 3
  • 23
  • 40
1

I was wrong.

To-day, the errors are back.

The reason appears to be that in the process of trying to sort this, I installed VS Community Edition 2019 to see if that worked OK (it did). Then went back to VSC, and - that was fine too. Later I uninstalled VS Community Edition 2019 (it is taking about 4GB). It was uninstalling that which brought the errors back into VSC. Reinstalled VS Community Edition 2019, and it is all fine again.

So, VS Community Edition 2019 installs something that VSC needs - but I haven't yet figured out what it is.

UPDATE:

Gave up. Never managed to find out what VSC wanted and wasn't getting. Instead, reinstalled old version of VSC (1.48.2 from code.visualstudio.com/updates) and it is all fine again.

nmw01223
  • 1,611
  • 3
  • 23
  • 40
0

If still having this problem, all you have to do to fix it is by going to Package manager and install "visual studio editor package"

windows>Package Manager> All Packages /or Unity Registry (depeding on your unity version) search of visual studio editor

if it's already installed delete it and reinstall.

Helmi
  • 83
  • 9
  • Found this: 'The problem is that the new .NET Core 3.1 SDK isn't supported by any current Mono release, so the setting "omnisharp.useGlobalMono" has been changed to "never" in 1.23.1 (see changelog https://github.com/OmniSharp/omnisharp-vscode/blob/master/CHANGELOG.md#1231-not-yet-released). This however is incompatible with Mono-based development e.g. Unity. In VSC, go to File > Preferences > Settings > Extensions > C# Configuration. Then change "Omnisharp: Use Global Mono" to "always".' I do indeed find no problem in 1.23.0, but it appears in 1.23.1. – nmw01223 May 27 '21 at 07:51
0

Got it FIXED! Solution (it was a Unity issue): In Unity, goto Edit > Preferences > External Tools > External Script Editor, and point it to Visual Studio.. Why this was so hard to find, I have no idea. But now my Photon solutions and namespaces properly transfer from Unity to Visual Studio. Hooah!

Also moved the script to where the photon scripts are

0

Uninstall the Visual studio community and re-install with latest VSC 2022. It will fix the issue