Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

MIDI or OSC for Unity Indie users?

Discussion in 'Formats & External Tools' started by VJ_Anomolee, Jan 19, 2009.

  1. Helgosam


    Feb 2, 2012
    Hi All

    Thanks for everything so far on this post - genuine question now:

    Having downloaded and running this successfully from dpentecost (many thanks):

    and running the scene called Hello3, I get the following error message:

    CompareBaseObjects can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.​

    It doesn't seem to stop the thing from working, but I am concerned, as when I export a more complex version for android it's not working, and I wonder if this might be what is causing the issue. The simple Hello3 version DOES work on android ok, but I'd still like to know if others are getting this error message, if so why, and how to fix it.

    Thanks, S:cool:
  2. elbows


    Nov 28, 2009
    That error has always been there for me. It hasn't stopped it working, but I do mean to look into it further, since its to do with threading and such issues should probably not be ignored. In terms of the implications from it that I've run into, I need to be careful with what code I run in the functions that are set to be run when a certain OSC message arrives. Specifically I avoid using Unity-specific stuff in such functions, as I have a suspicion they are being run in the separate thread that the OSC listener creates, rather than the main thread. So I mostly just modify basic variable types in those functions, e.g. change a float or set a trigger boolean, and then do the unity-specific actions based on the values of these variables in the usual Update function.

    Im not exactly a fountain of knowledge when it comes to threading, so Im sorry that my explanation is probably somewhat unclear and insufficient. I'll try to explain it another way if you let me know which bit needs further clarification, and I will post again if I get rid of the error message altogether.
  3. elbows


    Nov 28, 2009
    OK assuming you are only seeing that error message appear when you stop playing your scene in the editor, I have a fix. Its been a long time since I obtained the Osc package so I can't be 100% sure if its the same one you are using, but give it a try anyway:

    Look in Osc.cs for this line:

    if (OscPacketIO != null OscPacketIO.IsOpen())

    Replace it with this:

    if (OscPacketIO.IsOpen())

    In an ideal world I think a package that provides OSC support in Unity would do things a little differently so that there aren't any thread-related issues people may run into when writing their scripts that do stuff using Unity Engine, but Im afraid Im not the man for that job at this point in my development abilities.

    If you get other such error messages at points when your scene is actually playing, then its a likely indication that you've run into the thread issues I've been doing a poor job of explaining, and you should look at what you are doing inside functions that are being triggered by incoming OSC messages, and move unity engine specific stuff elsewhere.
  4. Henry_J


    Nov 9, 2012
    Hello All,

    I have come across Unity in the past few weeks, and am trying to control OSC messages to control a first person controller. I have used the example files on this thread, but when I try to implement it on a first person controller I have no communication. This is because I have no idea on how to implement the code. This is due to my lack of experience in the domain of C# and JS. I've wracked my brains over it for the past 3 nights, and still have nothing. I am sure its a simple fix. Would anyone have any examples of a character controller movements being controlled by OSC?

    I hope to contribute to the forums in the future with my knowledge with grasshopper and rhino.

    Any direction would be amazing!

    Thank you in advance.
  5. ASZYK


    Feb 27, 2013

    I was just wondering if anyone has been able to test the OSC implementation in Unity 4. I'm thinking of upgrading soon and haven't been able to test it as of yet.

    I have a big project coming up soon that requires it, here's an example of a previous test that I did using v3.>>

  6. jonbro5556


    Jan 1, 2013
  7. druffzy


    Sep 19, 2009
    Hi There,

    Is there a way to change IP address in real time through touchkeyboard input. Currently its working through initilizing pre-programmed IP address through setup(). It would be nice to know the ip address of the receiver and being able to change that in sender through real-time.

  8. Pi_3-14


    May 9, 2012
  9. heaversm


    Jul 12, 2011
    I did get stuck here with dpentecost's testSender example.

    I can successfully drive animations with the Receiver script, but when I attempt to send, I am unable to do so successfully without routing things through OSCulator. I am trying to send from Unity to touchOSC, and if I use the IP address and format:

    Code (CSharp):
    1. public var remoteIp : String = "";
    2. public var sendToPort : int = 9000;
    3. public var listenerPort : int = 0;
    5. oscM = Osc.StringToOscMessage("/1/push1");
    6. oscHandler.Send(oscM);
    I can see that touchOSC is receiving the message, because the light flashes red within the program, but the proper buttons are not lit up.

    However, if I route it through OSCulator, sending that same message to the iPad, it works.

    Any ideas what might be the issue? It doesn't like my string without OSCulator somehow.
  10. ToneSlaveMusic


    Oct 16, 2015
    Do you still have this scripts can you share. Or have anyone else managed to combine the scripts and are willing to share?
  11. Deleted User

    Deleted User


    For those that are playing with OSC and do not want to code, I've taken the scripts by Dave Pentecost and added a few scripts to control a game object transform, light, standard material fields, and other things, without requiring any coding. The scripts are fairly limited in what they can do, but they work and can be extended quite easily.
    Made for an artist friend with code fobia :)

    The scripts can be found at:

    and the readme briefly explains usage and limitations.

    Tested on Unity 5.6 beta, should work in Unity 5.x. Use at your own risk, and I cannot guarantee any support or assistance.
    Ben-BearFish likes this.