-
Notifications
You must be signed in to change notification settings - Fork 744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NetMQ + Unity3D, am I wasting my time? #631
Comments
I have a lot of the same concerns. I'm just learning NetMQ/ZMQ and it feels very fragile on Unity. Some guidelines and best practices to avoid editor freezes and crashes would be very helpful. |
Same problem to me.Unity will stuck. |
Try closing all sockets and adding NetMQConfig.ContextTerminate(); to the OnDestroy() event of the MonoBehaviour. This fixed all of my freezing issues. I am using AsyncIO.ForceDotNet.Force(); NetMQConfig.ManualTerminationTakeOver(); NetMQConfig.ContextCreate(true); and a single RequestSocket for my development scenario under Unity 5.4.1. |
Most of the issues of using netmq with Unity is stemming from not properly initializing it (using So, in my opinion you are not wasting your time and people are successfully using netmq with unity. You could try what others have been using. Are there any additional things which could help you getting started with unity? Maybe post your solution or add documentation to help others? |
|
@Sohojoe I quickly skimmed through the code and as far as I can tell it should work that way. |
@tobi-tobsen I didn't get the sense that this problem was related to those other MonoDev issues. I all I do is click run which the debugger attached; I'm not stepping through code or actually 'debugging' These are my ideas to move this forward, do you have other ideas?
I will try and get some more time on this over the holidays |
I also implemented the ReliablePubSub patterns; which also soft locks when using the debugger. |
@Sohojoe The included UnityMQ example locks up on second run, which I believe happens when you call NetMQConfig.ManualTerminationTakeOver(). This is behaviour that I experience when I have more than two sockets active. When I call close on the sockets, the actual low level socket object never receives a shutdown message, and so the context will never terminate as it awaits a successful shutdown message from each socket. Since you have the cleanup code at the start, it doesn't lock when you stop the editor (which triggers OnApplicationQuit()), but it will lock when the old context has yet to close due to the frozen sockets. Tested using Unity 5.5.0f3 on WIndows 10. |
I just went a long way to figure this problem out. The key is to have |
@Sohojoe Can you please tell me how you actually installed netmq on Mac OS X for use with Unity. Thanks |
@erdalpekel I had created a repro. I gave up on NetMQ for the problem I was hoping to solve, but I did update the repro with Unity 2017.1 / .Net4.6 - I think it is working now, but I didn't do deep testing |
I need to publish from Unity -> Python and also publish from Python -> Unity. I used @valkjsaaa code and it worked great for the Unity client and I can publish from Python. I haven't been able to figure out how to publish from Unity though, the server example is for req/res, not pub/sub. @Sohojoe I tried your code and the sample where it publishes and subscribes in a single script works fine. When I use my python script to try to listen to that IP and port it doesn't work. Is reliable server/client somehow different than pub/sub? |
@overthrowrobotics I gave up NetMQ and went with a mem cache solution (Redis) which is complex but well suited to my use case (Reinforcement Learning where I need to sync at up 1000 per seconds) What are you trying to do? There are a few different approaches. If you are not too worried about latency (and dont need to transfer too much data) then PubNub is super easy to set up. If you need something faster then it maybe worth looking at Unity's ML which uses sockets to comunicate between Unity and Python (it came out after I had figure out my path so I have not tried it but I belive it is open source). Initially I used HTTP / Rest which is pretty simple but not great for performance. |
Building a boxing robot. Here's an older version of it. https://www.youtube.com/watch?v=Bwv_wJbEbVE I have 5 Teensy (32-bit arduino clone) that I'm using for various encoders, pressure sensors, IMUs, LEDs, dollar bill acceptor, etc. Standard System.IO.Ports sucks. Super unreliable and I've tried 5 other 3rd party serial libraries and they are all problematic. Pyserial works pretty well. I managed to get mqtt/paho/mosquitto working last night. I'm only doing about 20hz with small <20 byte messages so I think it's going to be ok. I was thinking about the Unity ML but I couldn't find any documentation on how to hijack it's sockets. I use SARSA (similar to Q-Learning) in the robot through Aforge.net library since it was long before they released their ML stuff. It's not deep RL but for basic stuff it works. The problem is that there are a lot of new RL algorithms (even outside of deep) like contextual bandits that might work well and Aforge isn't being updated. |
I had a fully working setup using However I recently did some tests in 2017.3f3 and with the same setup the freezing upon Unity close or Assembly Reload has returned :( edit I think I jumped the gun on this. Reverted to 2017.2 and I am seeing the same problem. Which is very confusing as this was working fine a few months ago. The only other major change I am aware of (besides of course other work in Unity) was an upgrade in OS to Windows 10. |
After some more digging I discovered the issue. It works when Unity is set to use .NET 4.6, and hangs when set to the older option. |
Same issue found again here! |
Did you find any solution to this @rickyviking ? I'm currently investigating using NetMQ with @valkjsaaa's tricks to talk to some external processes like Python, C++ etc, and is interested to know if there are still serious problems with this. (Will try to update my own experiences, if I continue on this route). |
@samuell I didn't find a fix/workaround to make it work with that version of Unity. |
@rickyviking Thanks for the info, good to know! |
I'm having a suspicion now ... don't you need to do the I'm trying it now, but it results in Unity blocking ... which, according to the NetMQ cleanup docs is what happens when there are undisposed stuff left:
... so it seems the issue is doing more proper cleanup with NetMQ? |
Hey guys sorry I wasn't following this conversation. If it would still help, I can try and post the relevant pieces of our code. Everything has been working rather solid for almost the last year for us, the main key was using .NET 4.6 in Unity. 3.5 caused the locks. |
Thanks for the reply @jwvanderbeck ! I actually also just got it working, with .Net 4.x and a slightly customised (for our needs) version of @valkjsaaa 's code :) (Thanks @valkjsaaa and all who helped out resolving this!). I hope to find time to set up a proof-of-concept repo for what we did. Basically I think @valkjsaaa 's code works fine, but I implemented a component that does push/pull for exporting data too, as well as added the NetMQConfig.Clean() call in the Stop() method of the NetMqPublisher, to be called from OnDestroy() of the MonoBehavior object. |
What's the conclusion of the most bug-free way for communicating between Unity and other processes (e.g. python)? Is it still NetMQ? |
I gave up on zeromq a while ago and went to using websockets.
…On Tue, Aug 13, 2019, 7:37 AM Chanchana Sornsoontorn < ***@***.***> wrote:
What's the conclusion of the most bug-free way for communicating between
Unity and other processes (e.g. python)? Is it still NetMQ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#631?email_source=notifications&email_token=AHUKFBNKNGKFFLWJMEX6B43QELBJDA5CNFSM4CYNUGJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4F3TIQ#issuecomment-520862114>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHUKFBKLRF6K3CQZO4Q43GLQELBJDANCNFSM4CYNUGJA>
.
|
We switched to RabbitMQ. |
I am able to use NetMQ on Unity as a request client to connect to the python server fine.
With these 2 issues in mind, it's making NetMQ unreliable to use in production for me. @jwvanderbeck Can you make RabbitMQ work with Unity and python? And is there a nagging issue like something I mentioned above or something you are not satisfied with it? |
Thank you guys for the suggestions, I was really getting crazy about this freeze problem. |
@Oneiros90 You can still use |
Whats the latest update to this issue? I am having both editor freeze and memory leak issues using this code as a starting point https://github.com/sye8/Python-Unity-ZMQ |
Also had the freeze issues. For me it was NetMQConfig.Cleanup which was blocking. |
NetMQ seems great, was easy to connect my dotnet with Unity project. However, as soon as I wanted it to work in the editor rather than a build, it became a lot tougher for me to get it running smoothly. I thought I'd offer my code that works with Unity 2022.1 and NetMQ 4.0.1.6 as another example for others who come here with similar issues.
|
For those who wants to use NetMQ for Unity Editor extensions, domain reloads may mess with your sockets. You need to disable socket inheritance to close them properly. That's how Microsoft/Unity handled it in package com.unity.ide.visualstudio
I modified AsyncIO to reflect these changes here |
This issue hasn't received any update for quite a while, yet I want to share our recent experiences. We were using NetMQ 4.0.1.12, together with unity 2022.1.14.f1 and experienced sporadic message loss. This happened with the REQ as well as PUB sockets. Interestingly, when we caused a lot of traffic with the PUB socket from within unity our external subscribers lost messages roughly every 30s, but the messages that were lost were not the same. We did not have more time to look into any underlying issue, but replaced our usage of NetMQ with simple sockets, which worked flawlessly. |
I have been trying to implement a basic REQ/REP model with Unity3D (Mac OS X) acting as the server and python as the client. It works OK as a standalone Unity program. However Unity will soft-lock after 10-40 frames if i run with the Mono Develop debugger attached (requiring a Force Quit)
I have read through the numerous open and closed issues with regards to problems with NetMQ and Unity3D;
Is there a fundamental problem with Unity3D + NetMQ (i.e. I wasting my time with NetMQ and should look for an alternative)
or, is there a localized problem only when attaching Mono Develop debugger to Unity3D + NetMQ (i.e. NetMQ is good for production but I should look for another solution for debugging)
or, it's something hookey with what I'm trying to do (so either we debug that or I change my architecture)
Things I have tried
Environment
NetMQ Version:
(Note: I started with the Nuget version of NetMQ and AsyncIO; then I built locally from git.Master)
Operating System:
.NET Version:
Expected behaviour
Actual behaviour
Steps to reproduce the behaviour
The text was updated successfully, but these errors were encountered: