neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.07k stars 892 forks source link

[Info]How to avoid UNetWeaver errors #115

Open neuecc opened 8 years ago

neuecc commented 8 years ago

In Unity5, sometimes cause UNetWeaver Error. It is Unity's bug and does not resolved yet. http://forum.unity3d.com/threads/unity-5-1-unetweaver-errors.332268/

Mono.Cecil author mentioned about it, it is Unity's mono compiler bug. https://github.com/jbevain/cecil/issues/241

It can reproduce this code(it is very strange, unpredictable) https://gist.github.com/neuecc/6e9b53b74108ac8ecc90

How to avoid it? UniRx put under Plugins directory. Plugins is a special directory, it is comipled to Assembly-CSharp-firstpass.dll and is not affected uNET Weaver.

neuecc commented 8 years ago

5.2.0, changed under Plugin directory.

ZimM-LostPolygon commented 8 years ago

Still happens for me 100% even after moving to Plugins folder. I use Unity 5.3.2f1. UniRx 4.8.2 works fine.

neuecc commented 8 years ago

Oh, sorry... Would you please let me know other files in Plugins? I've received report when Plugins include UniRx + MarkUX + JSON.NET for Unity occurs uNET Weaver error. I don't have perfect solution. Certain solution is create dll. I wrote guide for build dll. https://github.com/neuecc/UniRx#dll-separation

ZimM-LostPolygon commented 8 years ago

There are no other files in Plugins, however, I have a lot of stuff in Standard Assets, which shares the compilation step with Plugins. It seems like the error doesn't depends on anything but UniRx. I don't have MarkUX or JSON.NET for Unity. I've tried moving some code around, and it works if there is less stuff in Plugins or Standard Assets. In my case, I've moved Master Audio out of Standard Assets and everything compiled fine. I've also moved UniRx to Standard Assets for consistency. https://dl.dropboxusercontent.com/u/12721305/Screenshots/Unity_2016-02-21_17-03-27.png

It seems like the error is triggered when the resulting assembly is getting huge in size. Moving UniRx to Plugins is not a solution at all. It does not depends on the assembly, but on the amount of code in the assembly.

It is also not true that Assembly-CSharp-firstpass.dll and is not affected uNET Weaver. It sure does, and it makes sense, since I could have some NetworkBehaviour classes in Assembly-CSharp-firstpass.dll, and Weaver should be able to process it as well.

I've also submitted another bug report to Unity with a lot of detail, hopefully it'll get fixed sometime...

In case I'll encounter this issue again, I'll try the DLL option, thank you.

SketchWork commented 8 years ago

Had similar problem with UniRx 5.3 and Unity 5.3.4P6. My solution was to move the contents of the UniRx folder into /Assets/UniRx/Plugins/

Tinche commented 7 years ago

I hit this today trying to integrate UniRx into our codebase. My solution was to download the nuget package (manually), unzip it and just stash the DLL from it somewhere into Assets/Plugins.

(Maybe one of these days I'll figure out a nice way of integrating nuget with Unity...)

ZimM-LostPolygon commented 7 years ago

Just a heads up: all these issues should be solved in Unity 5.5 once Mono compiler will finally be updated. The bug is in the compiler itself.

lucasmontec commented 7 years ago

I cannot build the DLL.... The guide for creating one is too shallow. How to link missing unity assembly?

neuecc commented 7 years ago

In default, UnityEditor.dll, UnityEngine.dll, UnityEngine.UI.dll uses in Library folder that is copy from Unity when opened project in Unity. https://github.com/neuecc/UniRx/blob/master/Dlls/UniRx/UniRx.csproj#L44-L52

If missing, you can copy dll from Unity's install directory. %UnityInstallPath%/Editor/Data/Managed %UnityInstallPath%/Editor/Data/UnityExtensions/Unity/GUISystem

silphid commented 7 years ago

I did multiple tests to try and figure out the UNetWeaver issues and my conclusion was that it was indeed a compiler issue. It think the reason it is a little unpredictable is because the compiler has issues when the generated DLL is too large. So if you have a small project, you won't encounter the problem, but as you add more and more code, you risk exceeding that threshold. Moving UniRx to the plugins assembly is only a temporary workaround, because adding more plugins will also eventually bust the OK size for that assembly.

The best solution I have found to avoid that problem completely is Alexzzzz's CSharp60Support, which allows to compile the code with the modern C# compiler instead of the old one. It works miracles and enables C# 6.0 syntax! For more info: https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration/src