UDP connections from Unity to Max

Yiannis Ioannides's icon

Hi folks,

I know that 50% of the question is not relating to Max/MSP, but it's all Javascript questions so there goes:

So I have created a middleware in Max/MSP, as my audio front-end, and I want it to be receiving basic integer data info from Unity, so it adapts audio based on Unity's gameplay.

Now, unfortunately I don't know any Javascript to help my situation, but I found this at it seems of some relevance, as for the interoperability of the two software, and specifically, from Unity to Max, which is what I care for. http://forum.unity3d.com/threads/4853-Max-MSP-communication?p=37572&viewfull=1#post37572

The guy wrote a Javascript script from Unity's end, to connect with Max through port 32000, and from Max's end, in the same posts, there's a compressed code, including the mxj net.udp.recv @32000 that seems to receive values in the "val0 val1 val2" format.

Now, looking at the Javascript code, with the very little scripting knowledge that I have, seems kind of straightforward; Seems like a test connection, generating random values for Max to receive from the other Max test patch, but it's not doing anything really. You'd expect to automatically update val0 and val1 in the Max patch, but nothing is happening.

Anybody has an input or previous experience on how to work these two together? Is there extra footwork to be done before the data parsing process starts? I hope I am not in the wrong side of the forum, just because there's too much Javascript here, if so, please let me know!

$Adam's icon

Hi,

there's a lot of code in the link you sent, it's not completely clear, to which code you are referring to. However, in general, if data is not arriving, you should double-check if all network addresses are set up properly (and, if the sender and receiver software are on different machines, then also the firewall settings).

Unfortunately I don't know Unity, but an important question would be, if data is being sent using some common format (like OSC) or not. If yes, then either net.udp.recv (or even better: udpreceive) should do the work. If not, you might give a try to my UDP-stream reader object called sadam.udpReceiver. You should also make sure that Unity is sending the data through UDP and not through TCP, otherwise it won't work. If you need TCP, you can use net.tcp.recv for OSC and sadam.tcpReceiver for non-OSC communication.

HTH,
Ádám

AudioLemon's icon

Glad you are still looking into this DeusNovus. A solution to using Max/Msp with a gaming platform would be greatly appreciated by many people.

Yiannis Ioannides's icon

Thanks so much for your answer Adam! From my research, people mostly use net.udp.recv for simple one-way data transfer, and I've been told that it's a "plug 'n' play" process, sticking the communication code somewhere in Unity and then Max will automatically start reading data flow through port 32000, by default. I really don't understand what's going on.

And grizzle, it has been such a frustrating experience, I've losing my hair over this, especially for a non-programmer. Hopefully, I will be updating you guys soon. You can all collaboratively help if you guys are into it, look into UDP/TCP code, simple data transfer examples from Unity to Max etc.

Anton's icon

Hello people, has there been any development on this subject since then ? By using net.udp.tecv i've only manage to get two lists of random numbers when I press play in unity, seems not to work properly..