valkjsaaa / Unity-ZeroMQ-Example

An example of Unity 3D 2017 works with NetMQ
79 stars 28 forks source link

Unity 5.6 compatibility #4

Open drstark opened 6 years ago

drstark commented 6 years ago

I'm trying to use this with Unity 5.6 and it doesn't work. As far as I can tell, the only reason is because it uses ConcurrentQueue which was added in .NET 4.0 and the version of Mono in Unity 5.6 is roughly equivalent to .NET 3.5. Do you have any plans to make a version compatible with 5.6, or does anyone have any suggestions on something that could replace ConcurrentQueue? I'm new to C# so I don't know all the various structures yet.

valkjsaaa commented 6 years ago

Can you check in Edit -> Project Settings -> Player, if Scripting Runtime Version include "Experimental (.NET 4.6 equivalent)"?

If yes, you can change to that version and most of the code in here should work. Otherwise, it wouldn't work anyways as this version of NetMQ requires .Net 4.0 or higher and I just can't get the older ZeroMQ to work at all.

ghorsington commented 6 years ago

@drstark

You can indeed get NetMQ working on .NET 3.5 equivalent version of Mono, but that requires some trickery.

I haven't looked too deeply into the issue (yet, at least), but it does seem that when the game uses "light" version of corlib (distinguishable but a much smaller System.dll in the built game -- just 1 MB combared to 1.6 MB), NetMQ has problems receiving messages. My use case is zerorpc-dotnet which uses XREP/XREQ sockets, but I too did have issues in Unity 5.6 games -- at least the ones that are bundled with lighter corlib.

My current solution is to either retarget the game to bundle the whole proper corlib or to add the full corlib after the game is built (or when one doesn't have game source available).
Of course, one can always revert to use something like clrzmq, but that should be only used as a last resort option.

As for ConcurrentQueue, you can of course make a shimmed version for .NET 3.5 using a normal queue and a lock (although that of course is not how real ConcurrentQueue is implemented, it's good enough for most basic use). Here is a very basic implementation example.