Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Max/MSP communication?

Discussion in 'Formats & External Tools' started by m1interactive, May 4, 2007.

  1. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    I've seen a couple posts relating to this, but seemingly no clear answer. Has anyone figured out an easy way to communicate data between Unity and Max/MSP? Perhaps OSC? The UDP method looks quite complicated-at least to me.

    Thanks!
    Brian
     
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Yep, there's a few people using Unity on this forum that would pee their pants with glee if an OSC or UDP plug would be written for Unity to talk with Max or SuperCollider.

    Anyone holding out? ;)
     
  3. jocphone

    jocphone

    Joined:
    Jun 26, 2006
    Posts:
    32
    Haven't persuaded myself to buy Max/MSP yet, but this quick example worked with Puredata.

    Just stick the following code on an empty Gameobect and for the PD server wire up a 'netreceive' on port 32000 feeding out to an 'OSCroute'. (I used pd-extended don't know if the base version has this)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.IO;
    5. using System.Text;
    6. using System.Net.Sockets;
    7.  
    8. public class PDCall : MonoBehaviour {
    9.  
    10.     private TcpClient client;
    11.     private Stream stream;
    12.     private ASCIIEncoding asen;
    13.  
    14.     void Start () {
    15.         client = new TcpClient();
    16.         client.Connect("127.0.0.1", 32000);
    17.         stream = client.GetStream();
    18.         asen= new ASCIIEncoding();
    19.         InvokeRepeating( "SoundUpdate", 1, 0.3f );
    20.     }
    21.    
    22.     void SoundUpdate () {
    23.         string msg = "/note " + (60+(int)(Random.value * 20)) + ";";
    24.         byte[] ba = asen.GetBytes(msg);
    25.         stream.Write( ba, 0, ba.Length );
    26.     }
    27. }
    28.  
    Only one way communication here but enough to get you started.

    Joc
     
  4. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    thank you Joc. This was just what I needed to get started.

    I had a lot of problems with the netreceive object crashing Max/Msp and had no luck using the mxj net.tcp.recv object.

    But after a lot of trial and error I've managed to rewrite your code from using Tcp to Udp. I also changed your code from C# to javascript.

    Code (csharp):
    1.  
    2. import System.Collections;
    3. import System.IO;
    4. import System.Text;
    5. import System.Net.Sockets;
    6.  
    7.  
    8.  
    9. private var client;
    10. private var asen;
    11.  
    12. private var msg : String;
    13.  
    14. function Start(){
    15.     client = new UdpClient();
    16.     client.Connect("127.0.0.1", 32000);
    17.     asen= new ASCIIEncoding();
    18.     InvokeRepeating( "SoundUpdate", 1, 0.5 );
    19. }
    20.  
    21. function Update(){
    22.     //
    23. }
    24.  
    25. function SoundUpdate(){
    26.     msg = "val0 " + Random.value * 20 + " : ";
    27.     msg += "val1 " + Random.Range(50,100) + " : ";
    28.     var ba : byte[] = asen.GetBytes(msg);
    29.     client.Send( ba, ba.Length );
    30. }
    31.  
    If anybody is interested I have include Max/Msp code

    Code (csharp):
    1.  
    2. max v2;
    3. #N vpatcher 339 116 1081 609;
    4. #P window setfont "Sans Serif" 9.;
    5. #P window linecount 1;
    6. #P newex 59 110 25 196617 iter;
    7. #P newex 59 157 20 196617 t b;
    8. #P newex 59 131 30 196617 sel :;
    9. #P newex 59 185 61 196617 zl group 10;
    10. #P number 105 244 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    11. #P number 59 244 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    12. #P newex 59 215 102 196617 route val0 val1;
    13. #P window linecount 2;
    14. #P comment 412 112 171 196617 only one receiving object can be bound to any one port.;
    15. #P window linecount 1;
    16. #P newex 59 88 150 196617 mxj net.udp.recv @port 32000;
    17. #P connect 0 0 8 0;
    18. #P connect 8 0 6 0;
    19. #P connect 6 0 7 0;
    20. #P connect 7 0 5 0;
    21. #P fasten 6 1 5 0 84 179 64 179;
    22. #P connect 5 0 2 0;
    23. #P connect 2 0 3 0;
    24. #P connect 2 1 4 0;
    25. #P pop;
    26.  
    Now I just need to make it receive data from Max.
     
  5. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    Hi Guys,

    Just wondering if you had any more luck communicating between Max and Unity. My specific purposes would be to send data from Max to control a Unity environment, most likely the POV of the world. Any thoughts or ideas?? I'm Max proficient, but not Java or C or anything else unfortunately.

    By the way, here's what we're working on:
    www.m1interactive.net

    My goal is to add a full 3d game engine into this, with the ability to control it all without touching a control, just moving your body, etc. Any help would be much appreciated. As soon as I get this communication working, I'll be needing some guys/gals to help come up with cool new content for it as well.

    Thanks!
    Brian
     
  6. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
  7. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    Thanks for the great comments and suggestions/help everyone. Bjerre, any chance you can talk me through how you made this work? The force is not strong with me in this stuff. Any help would be much appreciated!
     
  8. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Hi Brian

    I have made this simple setup showing how i use the server script and Max/Msp
    http://www.nonrelated.com/stuff/Max2Unity.unityPackage

    Im not sure its the best way to do this, because im not exactly a Jedi when it comes to C# and .Net, im properly more of a Youngling. But it works for me. I have just finished a 10 weeks robot workshop at school where this setup was used and it worked like a dream.

    the simplified Max/Msp patch.

    Code (csharp):
    1. max v2;
    2. #N vpatcher 6 47 660 696;
    3. #P origin 53 -16;
    4. #P window setfont "Sans Serif" 9.;
    5. #P window linecount 1;
    6. #P newex 240 144 27 196617 t b i;
    7. #P number 240 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    8. #P newex 201 144 27 196617 t b i;
    9. #P number 201 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    10. #P newex 164 144 27 196617 t b i;
    11. #P number 164 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    12. #P newex 127 144 27 196617 t b i;
    13. #P number 127 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    14. #P newex 89 144 27 196617 t b i;
    15. #P number 89 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    16. #P newex 89 181 180 196617 sprintf %i:%i:%i:%i:%i;
    17. #P comment 220 251 123 196617 number of active packets;
    18. #B frgb 157 157 157;
    19. #P comment 172 268 125 196617 there is a bug somewhere;
    20. #B frgb 157 157 157;
    21. #P comment 104 288 160 196617 we successfully transmitted data;
    22. #B frgb 157 157 157;
    23. #P number 183 249 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
    24. #P newex 258 232 54 196617 print info;
    25. #P newex 108 266 63 196617 print failure;
    26. #P newex 33 286 69 196617 print success;
    27. #P newex 33 210 236 196617 mxj net.tcp.send @address 127.0.0.1 @port 9349;
    28. #P window setfont "Sans Serif" 24.;
    29. #P comment 29 58 153 196632 net.tcp.send;
    30. #P window setfont "Sans Serif" 9.;
    31. #P comment 29 93 132 196617 sends TCP packets to Unity;
    32. #P fasten 10 0 2 0 94 203 38 203;
    33. #P connect 2 0 3 0;
    34. #P connect 11 0 12 0;
    35. #P fasten 12 0 10 0 94 171 94 171;
    36. #P fasten 12 1 10 0 111 171 94 171;
    37. #P fasten 14 0 10 0 132 171 94 171;
    38. #P fasten 16 0 10 0 169 171 94 171;
    39. #P fasten 18 0 10 0 206 171 94 171;
    40. #P fasten 20 0 10 0 245 171 94 171;
    41. #P connect 2 1 4 0;
    42. #P connect 13 0 14 0;
    43. #P fasten 14 1 10 1 149 171 136 171;
    44. #P connect 15 0 16 0;
    45. #P fasten 16 1 10 2 186 171 178 171;
    46. #P connect 2 2 6 0;
    47. #P connect 17 0 18 0;
    48. #P fasten 18 1 10 3 223 171 220 171;
    49. #P connect 19 0 20 0;
    50. #P fasten 20 1 10 4 262 171 262 171;
    51. #P connect 2 3 5 0;
    52. #P pop;
    53.  
    btw. I just added to line of code to the server.cs script, well two if you count comments. Check line 274 to see and line 273 to read.

    Bjerre
     
  9. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Hi again

    Just updated the the unity package. This should be easier to understand and it is more well documented. The link is the same.

    *Bjerre
     
  10. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    Hey guys thanks so much for the help. Sorry for the lengthy wait to say that. I got sidetracked and haven't had much time to play lately. I'll keep reply when I have some news of some actual progress though.
    Brian
     
  11. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    OK so I got my max patch up and running, plus the Unity project package you provided. Sorry to be ill-informed here.

    My goal is to send basically a start/stop message, plus x-y coordinates from Max. So if I send 3 variables from max, and they are received by Unity, how do I use the variables? Lets say I want an fps prefab to look left-right, up-down based on the x-y coords coming from max, and activate a particle system on the start/stop or whatever.

    I'm confused as to what the scripts do or how I should use them. I spent all weekend on this and it's driving me batty.

    Any help would be great!
    Thanks!!
    Brian
     
  12. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    If you are using the Unity package I made, the way to access the variables is through the GetVariable function located in the ServerRead script.

    Again if you use the above package find the GameObject named getVar. If you click on the attached script named GetVariables I have made an example where if you push the up key it will print the first value sent from Max/Msp, the line you are looking for is this:

    script.GetVariable(0);

    If you want the second value from Max you simply write something like script.GetVariable(1); and so on.

    hope this information was useful, if not feel free to send an e-mail.
     
  13. jbm

    jbm

    Joined:
    Jul 26, 2007
    Posts:
    2
    Hello, All.

    I've been working for a while on an interactive music composition app in java and max/msp. Lately I've been doing some interface work in Processing, but I'm kind of interested in something really immersive for the visual environment. It seems like a lot of the ideas I'm interested in would be a lot simpler to do in Unity than in Processing. Do any of you know whether Unity would be a good platform to create a visual environment from which to control a max/msp-based application?

    I guess I'm just asking how much you think I could do in terms of two-way communication between Unity and Max. I'm guessing that, since it's just like any app that communicates with its gui over the network, that it's the same deal in Unity... But not being a Unity user, yet, I'm looking to find out whether this might an avenue worth pursuing.

    Any and all thoughts appreciated.

    cheers,

    James.
     
  14. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    Sounds like you might be better using Jitter. Use it to get data from a camera or sensor, then apply it to a n MSP synth patch or something. Funny, I'm trying to go the other direction, sending motion data, extracted from camera movement to Unity. This way I can use Unity's graphic engine to build 3d worlds and have them controlled through Jitter (Max/MSP)

    Now if we could only get motion tracking data directly through Unity itself...
     
  15. jbm

    jbm

    Joined:
    Jul 26, 2007
    Posts:
    2
    Well, I'm using Processing right now, which can communicate with Max over the network. It's going okay this way, but it just sounds as though there would be a lot more "free" structure provided by Unity - everything has to be done basically by hand, from scratch, in Processing.

    Besides that, I'm really interested in taking some of the general paradigms from game design and applying them to music representation and control. I think there's a lot of untapped potential there, but I just need to find the right platform for the job.

    If anybody else has any comments or thoughts, I'd appreciate it. I think I'll download the trial anyway, but whatever info could help my decision would be great.

    J.
     
  16. brecht

    brecht

    Joined:
    Apr 24, 2008
    Posts:
    19
    Are there any developments on this since the last post?

    I've tried Bjerre's example project and it works, though after some time I get an error, and unity crashes. It says "SocketException: Too many open files"... Can someone shed some light on this?

    cheers,
    brecht.
     
  17. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can not have more than 255 open files at a time so files that are not needed anymore must be closed again
     
  18. brecht

    brecht

    Joined:
    Apr 24, 2008
    Posts:
    19
    I don't really know all the much of networking, and I am a newbie with unity (going through my 3rd day of the trial).
    The project uses the server.cs script to handle the connection, but I don't understand which "files" are open?
    When, indeed, 255 messages are sent from max to unity, the crash occurs.
     
  19. rdrink

    rdrink

    Joined:
    May 14, 2008
    Posts:
    1
    brecht
    I just joined the forum (this is my first post!) and thought I'd just chime in here...
    TCP/UDP sockets are handled as files
    This http://www.amk.ca/python/howto/sockets/ from Python (which of course Boo is based on) might help explain a few things.
     
  20. aaarrrgh

    aaarrrgh

    Joined:
    May 15, 2008
    Posts:
    10
    Hi,

    I have also been toying around with max/msp and unity, and getting them to connect to each other.

    To circumvent the problem with the 255 sockets, I used socket.close(); to properly close off the sockets after use. However, while this does mean that max runs for longer, it never quite fixes the problem. Instead, the connection seems to die after a few minutes.

    I am using the C# server posted on the wiki (that Bjerre refered to) for this.

    When I set the game to output the debug info, it appears to be using a whole bunch of ports, and I assume it dies when it comes across a port it is no longer capable of using? After a while, when the server dies, I get the "Error in Server :: DoIO()" error. I've attached a picture displaying the debug info. Anyone have any idea on how to, perhaps, reuse the old ports?

    I have also tried using socket.Disconnect(true) after closing the socket, but it just seems to force the error to appear quicker.

    Man, I hate networking. :)
     

    Attached Files:

  21. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72
    quick question.
    We are thinking of using Max to perform some audio stuff based on the position of the player in Unity.
    Any idea on what is required?
    Would be the Server script ok? Would it need some changes?
    Any experience on this?
    Basically we need to send position and rotation of player to max continuously.
    Thanks
    G>
     
  22. aaarrrgh

    aaarrrgh

    Joined:
    May 15, 2008
    Posts:
    10
    it's really easy to get max to send and receive data. just using the mxj object will do the job.

    However, the server on the wiki (as described in my post above) either dies after 255 messages received, or after a slightly longer while, if you choose to close down the sockets after use. I have no idea if this is also the case the other way around.

    I'm still looking at a method of reusing the sockets, but since my knowledge of .net is very limited, and I have 5 other tasks at the moment, so it is not really a priority, sadly. :)
     
  23. jt722

    jt722

    Joined:
    Jul 13, 2008
    Posts:
    1
    Hi Bjerre,

    It looks like it's been a while since you posted about this but your posts are extremely helpful.

    I was able to get Max talking to Unity with the Max code above and the server you pointed out:
    http://www.unifycommunity.com/wiki/index.php?title=Server

    Awesome. Thanks so much. But it appears your Unity package is no longer available at the link you gave:
    http://www.nonrelated.com/stuff/Max2Unity.unityPackage

    Any chance you can repost the package or point to another example?

    I have Max talking to Unity (I can see the Max data printed at bottom of Unity window) but I can't yet seem to do anything useful with the incoming data such as moving a game object or panning the camera.

    I know Max well but just started with Unity. Seems like you're a pro with both.

    James
     
  24. jjjack

    jjjack

    Joined:
    Aug 19, 2008
    Posts:
    22
    Has anyone gotten this to work? I have the same issue with Unity crashing after a "SocketException: Too many open files" error.
     
  25. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Hi everyone and sorry for not watching this thread for a looong time.

    I have made a lot of progress on this since my last post, I just totally forgot to post it - sorry for that.

    I have made a new package with a simple version of a Max/Msp to Unity setup that I have been using for a few projects.

    The Package : http://www.aneks.dk/_stuff/maxToUnity.unityPackage

    And a simple Max/Msp patch to test it
    Code (csharp):
    1.  
    2. max v2;
    3. #N vpatcher 617 122 1062 485;
    4. #P window setfont "Sans Serif" 9.;
    5. #P hidden message 91 69 14 196617 1;
    6. #P hidden message 69 69 14 196617 0;
    7. #P button 68 37 15 0;
    8. #P comment 234 139 33 196617 Depth;
    9. #P comment 195 139 33 196617 Height;
    10. #P comment 158 139 33 196617 Width;
    11. #P comment 109 139 33 196617 Z rot;
    12. #P comment 70 139 33 196617 Y rot;
    13. #P flonum 234 153 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
    14. #P newex 234 180 29 196617 t b f;
    15. #P flonum 195 153 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
    16. #P newex 195 180 29 196617 t b f;
    17. #P newex 31 240 51 196617 tosymbol;
    18. #P flonum 158 153 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
    19. #P newex 158 180 29 196617 t b f;
    20. #P flonum 108 153 35 9 0 0 0 3 0 0 0 102 102 204 222 222 222 0 0 0;
    21. #P newex 108 180 29 196617 t b f;
    22. #P flonum 70 153 35 9 0 0 0 3 0 0 0 74 156 97 222 222 222 0 0 0;
    23. #P newex 70 180 29 196617 t b f;
    24. #P newex 31 180 27 196617 f;
    25. #P flonum 31 153 35 9 0 0 0 3 0 0 0 204 140 140 222 222 222 0 0 0;
    26. #P newex 31 209 142 196617 sprintf %f:%f:%f:%f:%f:%f;
    27. #P newex 31 267 115 196617 udpsend localhost 2002;
    28. #P comment 31 139 33 196617 X rot;
    29. #P comment 30 38 34 196617 reset;
    30. #P hidden connect 23 0 4 0;
    31. #P connect 4 0 5 0;
    32. #P fasten 15 0 3 0 239 203 36 203;
    33. #P fasten 13 0 3 0 200 203 36 203;
    34. #P fasten 6 0 3 0 75 203 36 203;
    35. #P fasten 5 0 3 0 36 203 36 203;
    36. #P fasten 8 0 3 0 113 203 36 203;
    37. #P fasten 10 0 3 0 163 203 36 203;
    38. #P connect 3 0 12 0;
    39. #P connect 12 0 2 0;
    40. #P fasten 6 1 3 1 94 203 62 203;
    41. #P hidden connect 22 0 23 0;
    42. #P hidden connect 23 0 7 0;
    43. #P connect 7 0 6 0;
    44. #P fasten 8 1 3 2 132 203 88 203;
    45. #P hidden connect 22 0 24 0;
    46. #P hidden connect 23 0 9 0;
    47. #P connect 9 0 8 0;
    48. #P fasten 10 1 3 3 182 203 114 203;
    49. #P fasten 13 1 3 4 219 203 140 203;
    50. #P hidden connect 24 0 11 0;
    51. #P connect 11 0 10 0;
    52. #P fasten 15 1 3 5 258 203 166 203;
    53. #P hidden connect 24 0 14 0;
    54. #P connect 14 0 13 0;
    55. #P hidden connect 24 0 16 0;
    56. #P connect 16 0 15 0;
    57. #P pop;
    58.  
    Hope it will get some of you up and running
     
  26. bluedonkeyattack

    bluedonkeyattack

    Joined:
    Feb 27, 2008
    Posts:
    2
    Bjerre, Thank you so much for posting this. It really is super helpful. Excellent.

    All the best

    Kevin
     
  27. jjjack

    jjjack

    Joined:
    Aug 19, 2008
    Posts:
    22
    Yes, thank you. I was able to get the previous TCP example working by tweaking isConnected in Server.cs to not rely on the Mono socket exception and being sure to close sockets....but this UDP version is very clean!
     
  28. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Anyone else had trouble with this file? I just get gibberish. If someone would be nice enough to post a zipped version I'd really appreciate it.

    Ethan
     
  29. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Which file is it that you have trouble with Ethan ?

    If it's the unityPackage file, I have made a zipped version for you here: http://www.aneks.dk/_stuff/maxToUnity.unityPackage.zip

    Or are you refereeing to the Max/Msp code ? To use that just copy the code and in Max/Msp choose File / New from Clipboard

    hope that it was usefull

    / claus

    [Edit] Just saw your edit. I'm still using Max 4.6 and it'll be awhile before I can afford the update :(
     
  30. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Wow, that was fast!

    I'm still getting 3 folders full of nonsense when I unzip this. I must be doing something really stupid :?:

    Thanks for the tip on importing the text... I'd always save them out to a file and then open that up, but copy/paste is a heck of a lot easier :wink:

    [Edit]Nerver mind, I got it working with another extractor. I've put off playing around with this for way too long 'cause I just never have the time... this should be a fun night :wink:

    Thanks for sharing this with all of us!
     
  31. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    I just tried unzipping the file myself, and like you I get 3 nonsense folders. Must be the way that I compress the file that is wrong :?:

    But I found out that if you use Stuffit Expander you get the 3 nonsense folders + the unityPackage file :D

    / claus

    [Edit] I uploaded a max binary file if anyone would prefer that, http://www.aneks.dk/_stuff/Unity_Max.zip
     
  32. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Thanks a lot man, I got it all working. This is so cool! I might be up until dawn with this :D
     
  33. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    It's good to hear that you got it working

    / claus
     
  34. AaronDennis

    AaronDennis

    Joined:
    Apr 25, 2008
    Posts:
    4
    Bjerre, this is great work. I really appreciate it. Now, I may have a few questions soon...

    Best,
    Aaron
     
  35. VJ_Anomolee

    VJ_Anomolee

    Joined:
    Dec 23, 2008
    Posts:
    40
    ya this is great and has ALOT of potential
    right now Im trying to find a way to do realtime extrusions and post FX.
    to build something like Fijuu.com
     
  36. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Thanks for the Fijuu.com link, very interesting. And I promise to reply to your PM sometime this week if you're still having issues getting this to work... I've just been busy.

    Ethan
     
  37. VJ_Anomolee

    VJ_Anomolee

    Joined:
    Dec 23, 2008
    Posts:
    40
    ya Ive been very busy as well.
    Ive got a cube rotating and scaling in Unity with controllers in max via the UDP thing but want to push it further!
    Who wants to help?! (im still a noob coder)
     
  38. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
  39. moobla

    moobla

    Joined:
    Apr 1, 2011
    Posts:
    4
    Hi, would anyone know about how to change these examples around so that when you move the cube in unity the parameters would be shown in max? It doesn't haven't to be this example specifically just in general, i'm somewhat familiar to scripting, but if anyone could help me to set up a code that would work and the appropriate changes in max msp it would be greatly appreciated (need the connection for part of my final year project for uni )

    Cheers

    Oliver
     
  40. sacredgeometry

    sacredgeometry

    Joined:
    Dec 5, 2009
    Posts:
    55
    Incredible, thank you guys.
     
  41. Yiannis Ioannides

    Yiannis Ioannides

    Joined:
    Dec 7, 2011
    Posts:
    10
    +1 on "moobla"'s comment. I haven't downloaded [myu] yet, but there seem to be not many examples on the internet, demonstrating actual music/SFX operation from Max/MSP to Unity or vice versa. Anybody have any guidelines to follow or any tutorial videos, for all of us beginner to scripting?
     
  42. Jamcob

    Jamcob

    Joined:
    Dec 1, 2011
    Posts:
    3
    Is there any chance anyone can help someone who has no networking experience at all?

    I need some real help with this subject and I'm not sure how to connect everything together.

    I wan't to do what the Unity2max patch does so I can create music with the space invaders game, but I don't know where to start. Someone help please?
     
  43. Yiannis Ioannides

    Yiannis Ioannides

    Joined:
    Dec 7, 2011
    Posts:
    10
    Exactly, me too, make adaptive music based on the gameplay, mostly interested in Unity to Max, not the other way round. Anyone?
     
  44. rolandcahen

    rolandcahen

    Joined:
    Oct 1, 2010
    Posts:
    4
    Hello,
    Bjerre Max2Unity Package Works very well, but all the Unity2Max scripts I have been trying in the last week seem not to work anymore. Either because of the io which don't work the same way anymore in Unity 3.x version, or because there is a long latency, because the socket would not open, etc. Does someone have an efficient and simple solution, preferably in c#.
     
  45. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    It's been awhile since I made those scripts, and getting them up to date has been on my todo list for longer than I can remember :)

    I made this little script that works with Unity 3.51 and Max/Msp 6

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Net.Sockets;
    4. using System.Net;
    5. using System.Text;
    6. using System.Collections;
    7.  
    8. public class UdpServer : MonoBehaviour
    9. {
    10.     public string hostName = "127.0.0.1";
    11.     public int port = 7474;
    12.    
    13.     private UdpClient server;
    14.     private ASCIIEncoding byteEncoder = new ASCIIEncoding();
    15.    
    16.    
    17.     void Start ()
    18.     {
    19.         server = new UdpClient(hostName, port);
    20.        
    21.         server.Connect( hostName, port );
    22.        
    23.         // TEST //
    24.         SendFloat ("RouteArg0", Random.value);
    25.     }
    26.    
    27.  
    28.    
    29.     // Sends an Int value to Max //
    30.     public void SendInt(string maxRouteArgument, int val)
    31.     {
    32.         string message = maxRouteArgument + " " + val;
    33.         byte[] messageBytes = byteEncoder.GetBytes( message );
    34.         SendBytes( messageBytes );
    35.     }
    36.    
    37.     // Sends an Float value to Max //
    38.     public void SendFloat(string maxRouteArgument, float val)
    39.     {
    40.         string message = maxRouteArgument + " " + val;
    41.         byte[] messageBytes = byteEncoder.GetBytes( message );
    42.         SendBytes( messageBytes );
    43.     }
    44.    
    45.    
    46.     private void SendBytes( byte[] message )
    47.     {
    48.         try
    49.         {
    50.             server.Send( message, message.Length );
    51.         }
    52.         catch( SocketException e )
    53.         {
    54.             Debug.LogError( e );
    55.         }
    56.     }
    57.    
    58.     // Close server on exit //
    59.     void OnApplicationQuit()
    60.     {
    61.         server.Close ();
    62.     }
    63. }
    64.  
    I had a lot of problems with the normal udpreceive object in Max, so I ended up using the mxj net.udp.recv object instead.

    Let me know if it works for you

    Best

    Claus
     
  46. Garrettlynch

    Garrettlynch

    Joined:
    Dec 30, 2012
    Posts:
    4
    oops, ignore this. Latest version works fine.



    Hi

    I'm using the original Csharp script (below) which is throwing up the following error:

    SocketException: Connection refused
    System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy)
    System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP)
    System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point)
    System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port)

    The javascript version in this thread works fine with Max/MSP but I'm keen to stick to Csharp. Any idea what might be wrong? I'm using Unity 3.5.7f6 on OSX 10.5.8.

    Garrett


     
    Last edited: Dec 31, 2012
  47. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    How would you distribute a game that relies on max/msp or PD? The user almost certainly doesn't have them installed.
     
  48. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    This is a good question. Did you ever find out?
     
  49. MaxQuinonesSantander

    MaxQuinonesSantander

    Joined:
    Feb 20, 2020
    Posts:
    11