Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] OSC simpl

Discussion in 'Assets and Asset Store' started by cecarlsen, Jan 27, 2016.

  1. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi Darius

    Nice, thats a really neat Max trick!

    If we assume that Max treats intergers as 32 bit, then you should be able to convert them like this:

    Code (CSharp):
    1.  
    2. int intByteCount = sizeof( int );
    3.  
    4. // Convert int[] to byte[].
    5. int[] inputValues = new int[]{ 2, 3, 5, 7 };
    6. byte[] bytes = new byte[ inputValues.Length * intByteCount ];
    7. for( int i = 0; i < inputValues.Length; i++ ){
    8.     byte[] intBytes = System.BitConverter.GetBytes( inputValues[i] );
    9.     System.Array.Copy( intBytes, 0, bytes, i * intByteCount, intByteCount );
    10. }
    11.  
    12. // Convert byte[] to int[].
    13. int[] outputValues = new int[ bytes.Length / intByteCount ];
    14. for( int i = 0; i < outputValues.Length; i++ ){
    15.     outputValues[i] = System.BitConverter.ToInt32( bytes, i * intByteCount );
    16. }
    17.  
    18. // Compare.
    19. for( int i = 0; i < inputValues.Length; i++ ) Debug.Log( inputValues[i] );
    20. Debug.Log( "–>" );
    21. for( int i = 0; i < outputValues.Length; i++ ) Debug.Log( outputValues[i] );
    22.  
     
  2. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Did you try to disable "filterDuplicates" on your OscIn component?
     
  3. Electrino123456

    Electrino123456

    Joined:
    Feb 26, 2017
    Posts:
    21
    Dear Carl,

    Thanks for Your response and for Your patience.

    I did try to use Your code to decode bytes into ints in Unity but I get strange results:

    From Max I'm sending this:
    /test5 OSCBlob 8 1 2 3 4 5 6 7 8, bang

    I adapted Your code in Unity to work like this:

    Code (CSharp):
    1.   void OnTest5(byte[] bytes)
    2.         {
    3.             int intByteCount = sizeof(int);
    4.             int[] outputValues = new int[bytes.Length / intByteCount];
    5.             for (int i = 0; i < outputValues.Length; i++)
    6.             {
    7.                 outputValues[i] = System.BitConverter.ToInt32(bytes, i * intByteCount);
    8.                 Debug.Log("outputValues[i] = " + outputValues[i]);
    9.             }
    10.         }
    and each time I click on the Max message I get the console readout in unity like so:



    always two messages in the console even though max only sent one.... quite strange as I was expecting to receive:
    1
    2
    3
    4
    5
    6
    7
    8

    To reply to Your other question: Yes I did turn off filter duplicates while sending sequential ints from max to Unity, but even though I'm sending them quite slow (through speedlim 200ms object or even slower) I still only get the first and last number of the 8-int-long sequence in Unity.
     
  4. Electrino123456

    Electrino123456

    Joined:
    Feb 26, 2017
    Posts:
    21
    And when Filter Duplicates is OFF I still get 2 out of 8 different ints - just that those 2 ints are repeated a few times.
     
  5. Electrino123456

    Electrino123456

    Joined:
    Feb 26, 2017
    Posts:
    21
    Ok the ints and duplicates was an error on the max side - terribly sorry to bother You with that.
    It seems like event though the max console properly shows printing a sequence of ints sent to udpsend like so:
    1
    2
    3
    4
    5
    6
    7
    8

    It was still necessary to limit the speed of their sending to Unity to be properly discovered as a sequence of numbers.

    My previous solution with using speedlim was not working for some reason but limiting the numbers via metro wil zl queue and zlgroup did the trick.

    I'm only wondering if it would be possbile to make the transfer faster - 100ms seems like a long time for a few ints...
     
  6. Electrino123456

    Electrino123456

    Joined:
    Feb 26, 2017
    Posts:
    21
    I think it's about the timing of the sequence of numbers sent: when I am sending the ints much faster (each 10ms) Unity starts losing numbers - and only some of them go through. If I send each int every 100ms all works fine.
     
  7. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Possible causes for Blob issue:
    1) Perhaps Max is not sending 32 bit intergers. Could it be 16 bit?
    2) Perhaps Max is encoding the integers unexpectedly. Is the incoming bytes dividable by 4 (size of int)?
    3) Perhaps Max is swapping the bytes. Google "Little/big endian". You can try to swap the bytes.

    Regarding filterDuplicates ... is this happening when you send the list of integers as separate messages immediately (for example using the Max object Uzi)?
     
  8. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Yes, keep in mind that UDP is not reliable, you never know for sure if the messages go through, this is a general limitation of OSC based on UDP. Best practise is to send the values continuously and check for changes on the receiving side. I usually send messages with 16ms intervals from Max, that's close enough to 60fps on the Unity side.
     
  9. Electrino123456

    Electrino123456

    Joined:
    Feb 26, 2017
    Posts:
    21
    Dear Carl, THank You for Your response,

     
  10. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Perhaps try setting up a simpler source of ints in Max for testing, just to isolate the problem.

    To check if the byte array is dividable simply do Debug.Log( bytes.Length / (float) 4 ) and see if it returns a whole number.
     
  11. MikeChr

    MikeChr

    Joined:
    Feb 2, 2018
    Posts:
    26
    Hi. Is there a method of allowing OSCSimpl to process incoming OSC messages when Unity is in edit mode? Thanks!
     
  12. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi Mike. OscIn and OscOut are MonoBehaviours living in scene land and they are only ment to function at runtime. However, you can look at how the inspector panel for OscIn is implemented. It opens when the inspector is enabled (In Edit Mode!) and displays the incoming messages. You may be able to instantiate a OscIn object from an editor script (perhaps hiding it in the scene) and hook up a listener. However doing this is beyond the scope of my support and you will have to experiment yourself.
     
    MikeChr likes this.
  13. kulpajj

    kulpajj

    Joined:
    Aug 24, 2018
    Posts:
    8
    OSCSimpl was been really great - thank you so much for developing this. I recently ran into a limitation, though, where I am trying to generate a large bundle of many frequencies, amplitudes, and decayrates in Unity, to send into resonators~ in Max/Msp to make sound corresponding to what is happening in Unity. There are a lot of random parameters involved in generating these resonator sound models that make the size of the bundle fluctuate. Unfortunately, often I run into an error like this:

    " Failed to send message. Packet is too big (10828 Bytes)."

    Is there any way around this? I could port this resonator model script into Max and odot ( a scripting language in Max that works with OSC bundles ). I was just hoping to be able to do all my data operations in C# and Unity because I prefer it. Thank you for the guidance.
     
  14. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @kulpajj

    Thank you. I can recommend two remedies:

    1) Split messages into multiple bundles. Disable "bundleMessagesOnEndOfFrame" and modify your script to pack a fixed number of messages per bundle.

    2) Take a look at line 229 in OscOut. Try setting SendBufferSize to a larger number.

    The upcoming version of OSC simpl applies solution 1 automatically, but by checking the byte count instead of message count.

    Let me know if it works for you.

    All the best
     
  15. kulpajj

    kulpajj

    Joined:
    Aug 24, 2018
    Posts:
    8
    hmmm...searching OscOut for "SendBufferSize", the closest thing I have are lines 236 and 237 that are commented out as:

    // Set buffer size to windows limit since we can't tell the actual limit.
    //_udpClient.Client.SendBufferSize = OscHelper.udpPacketSizeMaxOnWindows;

    There is no line in this version of the script that actually sets the SendBufferSize. According to the versions doc with my assets package, the latest version appears to be 1.3.
     
  16. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Great you found the line. The reason it is commented out is because it needs further testing on different devices (it varies). Try uncommenting the line and setting the value of _udpClient.Client.SendBufferSize to something larger than 10828, say 16384. Of course, you will still get an error if you exceed the new value. The better option (1) is to split the messages into multiple bundles. A new version of OSC simpl (that is coming out very soon) automatically does this. UDP is not designed for very large packets, so it is recommenced to keep them small (less than 8192 to be safe).
     
  17. kulpajj

    kulpajj

    Joined:
    Aug 24, 2018
    Posts:
    8
    oh that's great. It works. Thank you so much! I didn't want to uncheck "bundleMessagesOnEndOfFrame", as that is my favorite feature! =-) I love and need my osc addresses streaming in Max all bundled up, not atomized. And I don't want to have to manage that by each script. A higher byte allowance per bundle is working so far.
     
    cecarlsen likes this.
  18. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    OSC simpl 2.0 is out and your garbage collector will love it!

    A lot of love has been put into making OSC simpl heap garbage free in the update loop. I use the package extensively myself, and GC hiccups has been a long standing issue for graphic performance in my projects when working with heavy streams of OSC packets. The update involves changes that may seem inconvenient at first, but they are necessary to avoid garbage generation. Please check the updated examples, especially "Optimisations", to fully benefit from the update.

    OSC simpl is now available for the price of a cortado ($5)!

    But why? Because a free alternative now exists; extOSC by Vladimir Sigalkin, an extensively featured, well crafted piece of work and I recommend it, especially for those who want to avoid scripting. Sigalkin decided to MIT-license extOSC last year, a generous gesture that one can't do anything but admire. So why at all continue the work on OSC simpl? Because I still prefer the API (biased of course), I use it in almost every project and need to be able to fix and extend things when needed. Why not free then? Because I think as long as we live in a monetary society, people should be payed for their work.


    NEW FEATURES

    – Introduced ZERO heap garbage in the update loop! (*1)
    – Added full two-way support for OSC 1.0 Address Pattern Matching.
    – Added support for the OSC argument type MIDI message.
    – Added OscMessage methods for containing common Unity types in blobs.
    – Added OscOut.splitBundlesAvoidingBufferOverflow option.

    *1) If used as advised and your strings and blob lengths don't change.


    IMPROVEMENTS

    – Updated examples to promote less heap memory garbage generation.
    – Added OscPool for message recycling. See the "Optimisations" example.
    – Streamlined inspector view of Osc.mappings.
    – Added method chaining to OscMessage.Add, also available for Set and SetAsBlob.


    CHANGES

    – Scripting Runtime Version .NET 3.5 is no longer supported. Set Unity
    to use .NET 4.0 in the player settings.
    – Deprecated OscIn.ipAddress. Use OscIn.localIpAddress instead.
    – Deprecated OscOut.ipAddress. Use OscIn.remoteIpAddress instead.
    – Deprecated onAnyMessage and added MapAnyMessage and UnmapAnyMessage.
    – Deprecated versions of OscMessage constructor and OscMessage.Add that
    accepts params object[] args.
    – Deprecated TryGetNull, TryGetImpulse and replaced with versions of
    TryGet to streamline method naming.
    – Removed Map() support for delegates, methods must be defined in objects
    that derrive from UnityEngine.Object.
    – Removed OscMessage.args and added Set() and RemoveAt methods.


    UPGRADE GUIDE

    This is a major update that can in worst case raise errors when upgrading existing projects. The breaking changes were implemented to completely avoid garbage generation from variable "boxing", a C# phenomena happening when casting primitive types to objects. Arguments are now stored internally as bytes. Here is an upgrade guide to ease your pain.


    1) Delete existing "OSC simpl" folder and import new version


    2) Enable .NET 4.x. Equivalent.

    OSC simpl no longer supports Scripting Runtime Version .NET 3.5. Open the Unity Project Settings panel, find "Player" –> "Other Settings" –> "Configuration" –> "Scripting Runtime Version" and set it to ".NET 4.x Equivalent".


    3) Fix `OscMessage' does not contain a definition for `args' error.

    The OscMessage.args field is no longer directly exposed. Arguments are now accessed via OscMessage using the methods Count(), Add(), Set(), TryGet(), TryGetArgType(), Clear() and RemoveAt().

    Old code:

    Code (CSharp):
    1. if( message.args[0] is string ) {
    2.     string name = (string) message.args[0];
    3.     DoStuff( name );
    4. }  else if( message.args[0] is int ) {
    5.     int index = (int) message.args[0];
    6.     DoStuff( index );
    7. }
    New code:

    Code (CSharp):
    1. OscArgType type;
    2. if( message.TryGetArgType( 0, out type ) ){
    3.     switch( type ) {
    4.         case OscArgType.String:
    5.             string name = string.Empty;
    6.             if( message.TryGet( 0, ref cueName ) ) DoStuff( name );
    7.             break;
    8.         case OscArgType.Int:
    9.             int index;
    10.             if( message.TryGet( 0, out cueIndex ) ) DoStuff( index );
    11.             break;
    12.     }
    13. }

    4) Fix param arguments warnings.

    OscMessage no longer supports params object[] args in constructor and Add methods.

    Old code:

    Code (CSharp):
    1. new OscMessage( address, value1, value2 );
    New code:

    Code (CSharp):
    1. new OscMessage( address ).Add( value1 ).Add( value2 );

    5) Fix delegate issues.

    OscIn.Map is no longer supports delegates. You must pass member methods now. This change was done to streamline the UI experience.
     
    Jon_Olive and ExT_rus like this.
  19. MohanJia

    MohanJia

    Joined:
    May 11, 2017
    Posts:
    1
    can someone tested if I can use it with Puredata?
     
  20. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    It works with MaxMSP, so it should also work with PD. If not, money back. Note that some OSC data types may not be supported by PD, such as boolean, color and MIDI message.
     
  21. Electrino123456

    Electrino123456

    Joined:
    Feb 26, 2017
    Posts:
    21
    Hi,
    I am sending a single parameter from Max/MSP to Unity 2019.2.0.b4.

    I experience a problem where messages are coming too fast and Unity tries to queue them and them spits them long after they stopped being propagated from max. This has an impact on the realtime interaction between the two programs.

    Is there any way of avoiding the incoming message queue?

    I tried lowering the resolution of messages sent from max but still the problem persists...
     
  22. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @Electrino123456. That sounds strange. If you can send me an example project with a Max patch I will look at it as soon as possible. I'm on my way on vacation so you may have to wait a week.
     
  23. suda_syng

    suda_syng

    Joined:
    Oct 3, 2019
    Posts:
    1
    Is there any particular reason why the current version of this asset requires Unity 2019.2.3? That seems unneccessary. Any chance you can upload a new version that at least supports 2018.x, possibly even going back to 5.x? Mobile VR development is a bit of a S***show in 2019 it seems; I need to stay in 2018 to have a coherent Oculus Go workflow.
     
  24. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    I will have a look. Would 2018.4 LTS be sufficient?
     
  25. SublimeDigital

    SublimeDigital

    Joined:
    Mar 27, 2019
    Posts:
    3
    I'm using OSCSimpl on ipad, ios 12.1.4 using unity 2019.2.6f1. Message being sent to oscin don't seem to be getting picked up. i'm sending osc messages from touchdesigner to the ipads ipaddress. I've tested using two desktops and the messages are being received fine. Is there anything specific you have to do to receive messages on iOS?

    I've attached a log, there's a few things that i'm not sure if they are causing problems.

    [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x113d0e410] get output frames failed, state 8196

    and

    <b>[ExposedUnityEvent]</b> Hack no longer working, most likely because of a update to Unity. Not found:
    AddListener
    OscSimpl.UnityEventReflection:LogNoLongerWorking(String)
    OscSimpl.UnityEventReflection:TryAccessPersistentCalls(UnityEventBase, Object&)
    OscSimpl.OscEvent`1:AddPersistentListener(UnityAction`1, UnityEventCallState)
    OscIn:Map(String, UnityAction`1, OscMessageType)
    ExitLightingToggleController:Start()

    Added screenshot which show that the upd messages are being received. but the mapped function isn't being called
     

    Attached Files:

    Last edited: Oct 22, 2019
  26. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Well that's something I was not hoping to see. It seems that reflection is no longer working as expected on iOS. OSC simpl is relying on UnityEvent for mapping addresses to methods at the moment. I am working on replacing UnityEvent with a custom event, but it may be a while before it is stable. PM me your email and I will send you early versions when ready.

    Thank you for reporting the issue.
     
  27. SublimeDigital

    SublimeDigital

    Joined:
    Mar 27, 2019
    Posts:
    3
    No problem. I've managed to get a work around working for my needs just now. If I call OSC.Map while on iOS i get the error but i noticed mapping setup in the editor works fine. Though manually adding this in the inspector was an issue as functions with OSCmessage as a parameter didn't show up on the list. So I use a editor script to call the map function on my OSCIn component and add the map in the editor. once built out it receives the messages ok. note it shows as function missing in the inspector but does actually work.
     
  28. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Happy to hear you found a work-around. The bug still needs fixing, it's on the todo.
     
  29. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    18
    Hi Carl

    Any news on this? I urgently need to get messages in and out of an iPhone and I'm having the same issue.

    @SublimeDigital - can you elaborate a little on your workaround?

    cheers

    Jon
     
  30. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    18
    So an update - I re-did all my input mappings in the inspector rather than by script and the error messages about the hack not working went away - however iPhone is still not receiving messages, alas...
     
  31. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @Jon_Olive I am aware of the issue (which was caused by a Unity update) and will fix it as soon as I get my hands free. I had a look a couple a weeks ago and din't find any quick and dirty fixes. Once I am past a gig next week I will find time to solve it properly. Sorry or the inconvenience.
     
  32. SublimeDigital

    SublimeDigital

    Joined:
    Mar 27, 2019
    Posts:
    3
    @Jon_Olive

    Hi Jon, Did you get this resolved? I used an editor script to add the input mappings like follows:


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;

    public class EditorAddMap
    {
    [MenuItem("Tools/SetOSCMapping")]
    private static void NewMenuOption()
    {
    OscIn osc = Selection.activeGameObject.GetComponent<OscIn>();
    OSCManager manager = Selection.activeGameObject.GetComponent<OSCManager>();

    if (osc != null)
    {
    osc.Map("/app/status", manager.OnStatusUpdate);
    }
    }
    }


    Ensure you have a game object in your scene selected with OSCIn on it, my gameobject also had a OSCManager script on it with the functions to be mapped and run thr script through the menu item button - Tools/SetOSCMapping. if it's a separate object with a component you need to call then you would need to multi select and change the code to get check for the components on each selected object.
     
  33. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    I have just submitted version 2.2.0 for review. It usually takes a couple of days for them to respond.

    This is a minor update without code breaking changes. However, mappings you have made in the Editor OscIn inspector may be forgotten, so you may have to set them up again. Sorry for the inconvenience.

    NEW FEATURES
    • The OscIn.Map methods can now bind methods that are not members of UnityEngine.Object and anonymous methods as well.
    IMPROVEMENTS
    • Redesigned the OscIn inspector Mappings section.
    • Removed onAnyMessage in OscIn and OscOut. The methods have been marked obsolete since version 2.0.0. Use MapAnyMessage and UnmapAnyMessage instead.
    INTERNAL
    • Replaced UnityEvent with a custom solution for storing and invoking OscMappings.
    • Improved OscIn.localIpAddress reliability.
    • Started using semantic versioning as promoted for Unity packages: MAJOR.MINOR.PATCH.
    FIXES
    • Fixed iOS build issue concerning OscIn mappings when they are defined in the inspector.

    OscIn 2.2.0 Inspector small.jpg
     
    Last edited: Dec 6, 2019
    SublimeDigital likes this.
  34. pbeard

    pbeard

    Joined:
    Aug 21, 2019
    Posts:
    3
    I'm using the latest available version of the code with Unity 2019.215f1. If I write the following in my Start() method:

    Code (CSharp):
    1.  
    2.     void Start() {
    3.         _oscIn.MapMidi("/synth", HandleNoteMessage);
    4.  
    5.         _oscIn.Open(7001);
    6.         _oscOut.Open(7001);
    7.  
    8.         List<OscMidiMessage> messages = new List<OscMidiMessage>();
    9.         messages.Add(OscMidiMessage.NoteOn(0, 60, 127));
    10.         messages.Add(OscMidiMessage.NoteOn(0, 61, 127));
    11.         messages.Add(OscMidiMessage.NoteOff(0, 61));
    12.         messages.Add(OscMidiMessage.NoteOff(0, 60));
    13.  
    14.         foreach (var message in messages) {
    15.             _oscOut.Send("/synth", message);
    16.         }
    17.     }
    18.  
    19.     void HandleNoteMessage(OscMidiMessage message) {
    20.         var note = message.data1;
    21.         message.GetTypeAndChannel(out var type, out var channel);
    22.         Debug.Log($"note = {note} type = {type}, channel = {channel}");
    23.     }
    24.  
    I see the following logs:

    note = 61 type = NoteOff, channel = Ch1
    note = 61 type = NoteOff, channel = Ch1
    note = 61 type = NoteOff, channel = Ch1
    note = 60 type = NoteOff, channel = Ch1


    Is it legal to send multiple messages in in a single frame? It looks like the messages are getting clobbered. If I rewrite it to send only 1 message per frame, like this:

    Code (CSharp):
    1.  
    2.     void Start() {
    3.         _oscIn.MapMidi("/synth", HandleNoteMessage);
    4.  
    5.         _oscIn.Open(7001);
    6.         _oscOut.Open(7001);
    7.  
    8.         List<OscMidiMessage> messages = new List<OscMidiMessage>();
    9.         messages.Add(OscMidiMessage.NoteOn(0, 60, 127));
    10.         messages.Add(OscMidiMessage.NoteOn(0, 61, 127));
    11.         messages.Add(OscMidiMessage.NoteOff(0, 61));
    12.         messages.Add(OscMidiMessage.NoteOff(0, 60));
    13.  
    14.         StartCoroutine(SendCoroutine("/synth", messages));
    15.     }
    16.  
    17.     private IEnumerator SendCoroutine(string address, List<OscMidiMessage> messages) {
    18.         foreach (var message in messages) {
    19.             _oscOut.Send(address, message);
    20.             yield return null;
    21.         }
    22.     }
    23.  
    then the logs look correct:

    note = 60 type = NoteOn, channel = Ch1
    note = 61 type = NoteOn, channel = Ch1
    note = 61 type = NoteOff, channel = Ch1
    note = 60 type = NoteOff, channel = Ch1
     
    Last edited: Dec 13, 2019
  35. pbeard

    pbeard

    Joined:
    Aug 21, 2019
    Posts:
    3
    Another workaround is to package all of the messages into a bundle:

    Code (CSharp):
    1.     void Start() {
    2.         _oscIn.filterDuplicates = false;
    3.         _oscIn.MapMidi("/synth", HandleNoteMessage);
    4.  
    5.         _oscIn.Open(7001);
    6.         _oscOut.Open(7001);
    7.  
    8.         List<OscMidiMessage> messages = new List<OscMidiMessage>();
    9.         messages.Add(OscMidiMessage.NoteOn(0, 60, 127));
    10.         messages.Add(OscMidiMessage.NoteOn(0, 61, 127));
    11.         messages.Add(OscMidiMessage.NoteOff(0, 61));
    12.         messages.Add(OscMidiMessage.NoteOff(0, 60));
    13.  
    14.         OscBundle bundle = OscPool.GetBundle();
    15.         foreach (var message in messages) {
    16.             bundle.Add(OscPool.GetMessage("/synth").Add(message));
    17.         }
    18.         _oscOut.Send(bundle);
    19.         bundle.Clear();
    20.         foreach (var packet in bundle.packets) {
    21.             OscPool.Recycle(packet);
    22.         }
    23.         OscPool.Recycle(bundle);
    24.     }
    25.  
     
  36. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Thank you @pbeard for reporting this issue, I am able to reproduce it. For a quick fix while I'm working, turn on "bundleMessegesOnEndOfFrame" in the OscOut component.
     
  37. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    It turns out that when sending multiple individual UDP messages immediately after one another the data is lost between sending and receiving socket. If I add Thread.Sleep(10) between the messages then they go through as expected. This is both the case on MacOS and Windows. I haven't encountered this before and wonder if this has to do with an update to Unity.

    There is an update on the way that fixes the issue by bundling messages by default. Multiple bundles does not seem to have this issue, which I suspect has to do with their larger byte size.

    EDIT: The new version is up.
     
    Last edited: Dec 20, 2019
    pbeard likes this.
  38. pbeard

    pbeard

    Joined:
    Aug 21, 2019
    Posts:
    3
    Thanks. I've confirmed that your workaround works.
     
  39. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,340
    Cool Project, I'm on Android, does this work?
     
  40. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi. I don't have an android device, so I can't offer support on that platform. I may work, that's all I can say unfortunately.
     
  41. ruvidan2001

    ruvidan2001

    Joined:
    Apr 5, 2020
    Posts:
    6
    I'm a little newer to Unity and bought your oscsimpl. I come from Touchdesigner but still learning ropes with Unity.

    Let's say I wanted to move the position of a 3d box. I drag the OSC IN into the box and set the Mappings to box / Transform.I see the Messages box is receiving the OSC signal so communication is good, but where do I go to further assign that to transform.position.x ? I couldn't find in the documentation where I'd edit the code or if I needed to drag any other C# snippets ? Thanks!
     
  42. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    If you want to map multiple arguments like XYZ to a single property, like transform position, you need to write a receiver script. Try have a look at the GettingStartedReceiving.cs script in the Examples folder. The reason that there are no readymade scripts for this, is that the incoming values can be packed in different ways. XYZ values could be packed in a single message, in three messages. The value types could be floats, doubles or ints. And there could be other arguments in the same message. To keep things simple, that flexibility is left to the user.

    Let me know if it helps.
     
  43. ruvidan2001

    ruvidan2001

    Joined:
    Apr 5, 2020
    Posts:
    6
    Thank you! It worked like a charm. I am just a bit new so I had to learn a few other things to grasp this better.
     
    cecarlsen likes this.
  44. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    hi @cecarlsen , I just bought the asset from the store - and being a newbie (and non code capable) I've tried my best to get it working to drive a Unity Camera field of view/focus from an android phone but am failing miserably.

    I downloaded a free OSC gui/sender from the playstore: https://play.google.com/store/apps/details?id=com.ffsmultimedia.osccontroller&hl=en

    My question: Am I doing something wrong or missing some core script to get things working? Currently I've added the Osc In script to the camera and configured as in the attached screenshots, but I cant get the camera to change fov or indeed, and messages to go from the android phone itself. I know the network works because I'd earlier used the Unity Webrtc demo and it worked on my home network.

    Hoping you can help get me started.
    Kind Regards.


    I'd earlier bought (and returned) TouchOSC because others have also complained the app does locks onto a private IP instead of local network IP
     

    Attached Files:

  45. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Hi @cly3d sorry to hear you are having trouble.

    First off, OSC simpl does not support Android officially, as stated in the Asset Store description. But that is just because I don't own an Android device to test on. That said, It may work.

    If you don't see messages coming in in the OscIn inspector, then the connection is not there. There is a section in the manual about trouble-shooting this. Let me know if you tried all of that ... for example ensuring that the Unity Editor app is not protected by a firewall.
     
  46. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    Yes, Ive turned avast off,. and windows firewall allows Unity through. (that's how the Unity WebRTC demo runs)
    I didn't know it would'nt support android, but it's ok, considering the price of the asset.

    What I do want to know is, so far the steps I've taken should have had some values streaming in, correct?
    Or am I missing placing some important script or "path"
    Is the path in the screen shots the correct way to go?

    Thanks.
     
  47. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    [Solved] Omg! I feel so silly. It works. I double checked the firewall settings and because I have Unity 2018 and 2019 and 2019.3.10 the 2019.3.9 for some reason was blocked in firewall rules

    Thank you so much! I'll make sure I leave a review on the asset store
     
    Last edited: Apr 20, 2020
  48. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    I've actually made that mistake myself a couple of times =)

    Appreciated!
     
  49. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    122
    arperture_OSC.JPG Hi @cecarlsen , I hate to be a bother, but I could use your help on this.
    Using OSCsimpl has made it so easy to control so many parameters in Unity (cameras, objects).. even lights!

    What I'm having trouble is with the fact that Unity has some quirks. for instance on the normal Physical Camera component when dropping in an OSC In script it exposes parameters such as focal length etc - which I've been able to map to an android phone Osc app.

    However, "aperture" is not exposed - and a thread says here that it's in a separate 'HDAdditionalCameraData' script that's attached by default to the Unity physical camera
    https://forum.unity.com/threads/hdrp-cant-find-aperture-through-scripting.705899/

    How can I access this via OSCsimpl, could you help please?
     
  50. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    606
    Yes. That is because the variable is too nested for the editor drawer to handle. Perhaps I will deal with this if a lot of scripts start using that design pattern.

    Try this out. Add it to you camera and set the oscIn reference in the inspector.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering.HighDefinition;
    3.  
    4. [RequireComponent(typeof(HDAdditionalCameraData))]
    5. public class HDCameraAppatureMapping : MonoBehaviour
    6. {
    7.     [SerializeField] OscIn _oscIn = null;
    8.     [SerializeField] string _appatureAddress = "/hdcam/appature";
    9.  
    10.     void Awake()
    11.     {
    12.         HDAdditionalCameraData data = GetComponent<HDAdditionalCameraData>();
    13.         _oscIn.MapFloat( _appatureAddress, ( float value ) => data.physicalParameters.aperture = value );
    14.     }
    15. }
     
    Dirrogate likes this.
unityunity