Search Unity

[RELEASED] OSC simpl

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

  1. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    157
    Sorry for being so dumb in the coding dept, @cecarlsen I didnt know where to add this bit
    I tried creating a new C# script and copy pasting but it wont does not work, and if I add it the actual HDAdditionalCamera script it throws up a bunch of errors.
    Is this a standalone script that I add to the camera component stack?

    Sorry for the Noobness. If you do update OSCsimpl to take care of these nested scripts it would be a boon!
    For instance - the new Hdrp Volume stack (fog, Depth of field, Bloom etc.,,) these parameters can't be accessed by just dropping the "Volume" object in the inspector.

    **Edit** Ok it works! I had to name the script the same as the public class - noonbness 101:rolleyes:

    Thanks again for the help!
     
    cecarlsen likes this.
  2. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    157
    Hi @cecarlsen ,
    OSCsimpl has been a great bridge for allowing non coders such as myself to gain quite a bit of control over Unity.

    I'm reaching out again, as one aspect has me stumped.
    I'm using the CineMachine package (from Unity Package manager) - and have setup two Cinemachine Virtual cameras.
    The way things work with Cinemachine cameras is, you can blend/switch between them based on a 'Priority' field which takes in integer numbers.

    However when I create (using Touch designer on cellphone) either a slider with value of say 1 to 10 or a push button to send a single value of 10, I get a console error in OSCsimpl about int v/s float as in the image below
    int_versus_float.JPG

    Ideally I want to use a slider to blend between Virtual Cameras in Cinemachine under Osc control.
    However, I don't mind just being able to "switch" between two cameras based on their priority being higher.

    If you could spare some time to solve, I'd be grateful.
    Kind Regards
     
  3. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    So, OSC simpl is "[...] designed for those who love the flexibility of scripting". Most times, sending and receiving will involve writing a script.

    In this case, you are receiving a value of type float that you would like to send to a property setter of type int. The OscIn mapping UI does not support casting. This has to be done in a script.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3.  
    4. public class FloatToIntMapping : MonoBehaviour
    5. {
    6.     [SerializeField] OscIn _oscIn = null;
    7.     [SerializeField] string _address = "/oscControl/steadyCam";
    8.     [SerializeField] IntEvent _intEvent = null;
    9.  
    10.     // Wrapping the generic UnityEvent is no longer necessary in 2020.1.
    11.     [System.Serializable] public class IntEvent : UnityEvent<int>{ }
    12.  
    13.  
    14.     void Awake()
    15.     {
    16.         _oscIn.MapFloat( _address, OnFloatReceived );
    17.     }
    18.  
    19.  
    20.     void OnFloatReceived( float value )
    21.     {
    22.         _intEvent.Invoke( Mathf.RoundToInt( value ) );
    23.     }
    24. }
     
    Last edited: May 7, 2020
    Dirrogate likes this.
  4. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    157
    Thank you so much! it works as expected.
    I'm slowly coming to understanding the inner workings of these aspects, while contributing the results and feedback directly to Unity.
    For instance I'll be now writing to the team at Cinemachine - to include or recommend assets such as OSCsimpl for Virtual Cinematography... along with some other settings that should be exposed (which I now realize they aren't, thanks to the OscSimpl script)
     
    cecarlsen likes this.
  5. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    157
    @cecarlsen For a $5 asset, the support shown on these forums is outstanding. I'd gladly pay double or three times the price for built in features such as dealing with accessing deep nesting of parameters in the editor and also for the ability to do casting (a term I learned from you) intuitively within the OSCsimpl gui - from float to Int.

    I've made much progress with using OSCsimpl with TouchOsc. For instance, at the start of video below, the room light flicker is not a script, but me manually moving a TouchOSC slider. Likewise, the changing of (Cinemachine) cameras.


    Help needed (again)
    I know in message https://forum.unity.com/threads/released-osc-simpl.382244/page-2#post-5697976
    @ruvidan2001 figured out how to move a box. I tool a look at the Getting started Oscin script but yeah, it's still above my coding ability.

    What I want to do is, to use the output from this app: https://sensors2.org/osc/ to pan/tilt a Unity Camera.
    I've got the app successfully sending Gyro, accelerometer and orientation values to OSCsimpl as in the screenshot
    Gyroscopevalues_osc.JPG
    My roadblock is how do I drive the transform of the Unity Camera with these values?
    I know this is spoon-feeding, but my coding skills are up to zilch and hopefully, it will benefit others with zero skills but big plans.

    Kind Regards.
     
    Last edited: May 12, 2020
  6. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @Dirrogate

    Here is an example of receiving three arguments of type float and forwarding them as a Vector3.

    You will probably have to scale and translate the incoming values to fit your needs. It looks like the incoming orientation is measured in euler angles. If you so, you can use Quaternion.Euler() to convert to a Unity compatible rotation. This however is beyond the support for OSC simpl.

    I recommend the scripting courses available under Unity's Learning sections.
    https://learn.unity.com/course/beginner-scripting

    If you are interested in manually controlling the camera, I can also recommend using the 3D Connexion Space Mouse. I use it for controlling the camera freehand for live concert visuals. The sensitivity is great and it can give a live feel to the scene that animated transitions can't. As far as I know, Unity's new Input System supports it.

    All the best
    Carl Emil


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3.  
    4. public class FloatArgsToVector3Mapping : MonoBehaviour
    5. {
    6.     [SerializeField] OscIn _oscIn = null;
    7.     [SerializeField] string _address = "/accelerometer";
    8.     [SerializeField] Vector3Event _vector3vent = null;
    9.  
    10.     // Wrapping the generic UnityEvent is no longer necessary in 2020.1.
    11.     [System.Serializable] public class Vector3Event : UnityEvent<Vector3>{ }
    12.  
    13.     void Awake()
    14.     {
    15.         _oscIn.Map( _address, OnMessageReceived );
    16.     }
    17.  
    18.     void OnMessageReceived( OscMessage m )
    19.     {
    20.         // Try get values and return early if we fail.
    21.         float x, y, z;
    22.         if( !m.TryGet( 0, out x ) || !m.TryGet( 1, out y ) || !m.TryGet( 2, out z ) ) return;
    23.  
    24.         // Forward!
    25.         _vector3vent.Invoke( new Vector3( x, y, z ) );
    26.     }
    27. }
     
    Dirrogate likes this.
  7. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    157
    Thanks so much again, Carl.
    I tried out the script, and yeah it would need scaling to turn the camera as smoothly as can be done with a mouse.
    I'll stick to a backup (and more scalable) solution of using a VR controller such as the oculus hand controller instead.

    I'll certainly benefit from learning scripting, and intend to get cracking once these higher level workflows get done (for Virtual Cinematography).
    The thing is, using Unreal Engine is all so plug n play and ready to go in the Virtual Production arena, I'm actually punishing myself (in a good way) by sticking it out with Unity, thereby building a solution from scratch.

    I just like Unity's somewhat more friendly and intuitive approach to gluing things together.
     
    cecarlsen likes this.
  8. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    Dear Carl
    Thanks for your amazing asset. I use it quite frequently. I have a question though.

    I saw that you are using an async task for receiving the osc messages. I also saw that you are queuing up the received osc messages.

    let's say I am receiving multiple messages during one frame. are they queued up so I can dequeue them in the update loop?
    If so, how would I do that?

    I am using the following (simplified) code:

    Code (CSharp):
    1.     Dictionary<string, MyClass> allData = new Dictionary<string, MyClass>();
    2.     OscIn receiver;
    3.     void Start()
    4.     {
    5.         if (receiver == null) receiver = gameObject.AddComponent<OscIn>();
    6.         receiver.Open(12345);
    7.         receiver.Map("/SomeAddress", OnReceivedEulerAngles);
    8.     }
    9.  
    10.  
    11.     void OnReceivedEulerAngles(OscMessage message)
    12.     {
    13.         MyClass h = new MyClass();
    14.         message.TryGet(0, out h.PitchYawRoll.y);
    15.         message.TryGet(1, out h.PitchYawRoll.x);
    16.         message.TryGet(2, out h.PitchYawRoll.z);
    17.         message.TryGet(3, out h.id);
    18.         if (allData.ContainsKey(h.id))
    19.             allData[h.id] = h;
    20.         else
    21.             allData.Add(h.id, h);
    22.     }

    whereas potentially I receive several osc messages during one frame with different id's. Depending on the ID I would like to update my Dictionnary

    allData


    how would that be possible? Thank you so much.
     
    Last edited: Jun 5, 2020
  9. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @aivo, sorry to hear you are having issues. First, did you uncheck “filterDuplicates” on the OscIn component? When enabled, if multiple messages with the same address is received, only the newest is passed on.

    EDIT: From version 2.3.0 and onward, filterDuplicates is set to false as default.
     
    Last edited: Jul 1, 2020
  10. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Awesome plugin. How to get it working on Android?
     
  11. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Thank you, if you feel like that, please do rate it ;)

    I don't have an Android device at my disposal, so I don't provide official support for that platform. That said, it may work.
     
  12. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    On my side I had no problem deploying to android. Just switch platform and build&run. Do you have any specific problems?
     
    cecarlsen likes this.
  13. Ikakhi

    Ikakhi

    Joined:
    Apr 19, 2019
    Posts:
    1
    i @cecarlsen ,

    Came across OSC Simpl trying to figure out how to lannex to Unity. I found your script so script much more simpler to load in the Unity so thank you for that?. I am still quite a new to Unity and there aren't any tutorials on lannex to Unity integration. What would be the steps to connect Iannex to Unity, I would really appreciate some pointers thanks!
     
  14. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @Aike-A

    When I launched OSC simpl, years ago, I tested connection with Iannix and it worked fine.

    There is a video here showing how osc messages are send from Iannix.


    To understand how to receive them using OSC simpl, please refer to the manual and the examples. It will go someting like this:
    1) Make sure that Iannix is sending to the IP of the machine running Unity, or 127.0.0.1 if it runs on the same machine. And choose a valid port, for example 8888.
    2) In Unity, add an OscIn component to an object in your scene. In the inspector, set the same port (8888).
    3) You should see messages flowing in the inspector.
    4) The manual and the examples shows you how to forward the message arguments to the methods you desire.
     
  15. aivo

    aivo

    Joined:
    Feb 13, 2017
    Posts:
    30
    Hello again.

    I found the following behavior:
    If during one frame I send multiple messages to the same ip address and the same port but to different OscAddresses, OscSimpl automatically generates an OSC bundle.

    Can I switch off this behaviour? Because the recipient cannot handle bundles.

    thanks
     
  16. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @aivo

    I see. I was not aware of libraries that don't support bundles. What library/software is on the receiving side?

    In earlier versions of OSC simpl, automatic bundling was optional. However, it turned out that messages that are send successively without bundling are very prone to be lost. So I forced automatic bundling as default.

    In the upcoming version (2.3.1), I've brought the option back in, and added some warnings. Send me an email and I'll send you the version right away. It may be a few days before it is available on Asset Store.

    All the best
    Carl Emil
     
    Last edited: Jul 23, 2020
  17. dfarjoun

    dfarjoun

    Joined:
    Aug 6, 2017
    Posts:
    42
    Hi,
    Instead of using touchOSC or TouchDAW, is it possible to create an app similar to these with OSC-Simpl?
    So I could create my interface and communicate not only with Unity applications via smartphone, but also DAW (digital audio workstations like Reaper) or Lightroom, for example. These ones might receive midi messages, right?

    It it possible?
     
  18. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Yes, totally possible. I used TouchOSC for a long while, but eventually I got annoyed with it's limitations. You can use Unity UI (Canvas) and OSC simpl to create very custom multi touch remote control apps for DAW's and other software that supports OSC.

    OSC simpl supports "MIDI over OSC", meaning that a MIDI message is stored and send as an argument to a OSC message. This is not the same as pure MIDI. As far as I know, only very few apps support "MIDI over OSC", although it is part of the OSC specs v. 1.1. In short, if you also want to send pure MIDI, you will need to look for an additional MIDI extension for Unity.

    All the best
    Carl Emil
     
  19. dfarjoun

    dfarjoun

    Joined:
    Aug 6, 2017
    Posts:
    42
    Thank you very much for the reply. I've sent a DM with some details, if you don't mind.
     
  20. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    157
    @cecarlsen OSC simpl has played a big role in allowing me to create a Virtual Production pipeline in Unity even with my limited skills (coding) . Thanks again for all the help. Here's a finished film I did while using the asset.
    (lights flickering controlled by slider over OSC, switching Cinemachine cameras over OSC etc)


    I'd like to invite you to join the Facebook Unity Virtual Prod. group. https://www.facebook.com/groups/892348284544650/
    Your insights would be valuable to all.

    On another note, I think I saw in one of the forums - your quest for Cluster rendering and why Unity removed it.
    Today, UE is leading the way in Virtual Prod, because of cluster render (nDisplay)
    Your asset Off-axis camera is another great component in Virtual Prod. Did you solve the Unity cluster rendering debacle?
    I was investigating UniCave https://widve.github.io/UniCAVE/
     
  21. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Super nice to hear @Dirrogate =)

    I haven't checked up on the state of cluster rendering recently, so I can't really tell if it's dead or alive. Yes, Unreal is the standard choice for virtual production these days, I hear this from many. Unity has clearly neglected the sector. Also, they have made life really hard for those of us who try to extent the engine to do things beyond the scope of their imagination. My hope is that when the HDRP and URP shader libraries and GraphicsBuffer implementation (index and vertex buffers) starts to solidify, we will see a new wave of tools from the community that will give Unity an edge in virtual production.
     
    youri_ssk and Dirrogate like this.
  22. pym4742

    pym4742

    Joined:
    May 14, 2020
    Posts:
    12
    Hello, Carl Emil Carlsen.
    I am a student who purchased OSC simpl you made for audio visualization using Max for live and Unity.

    I want to ask you a question because I have a question while watching Script.

    1.What is the difference between Getting Started Receiving in the Getting Started folder and OscIn in the Runtime folder?

    I know how to use OscIn.
    But when do you use Getting Started Receiving?

    2.How do you extend the range of mapping?

    I want to map the scale of Sphere, but I can't find it in Mapping.
    Is this a problem that I can fix by scripting myself?

    And I wonder if it is possible to move the value from OscIN to VFX Graph.
     
  23. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @pym4742

    1. It sounds like you have imported the new version (with Unity's recommended folder structure) on top of an old version (that has no Runtime folder) so duplicates are appearing. There should only be one "Getting Started" example scene.

    2. The OscIn inspector only has mappings for single argument OSC supported types. If you want to scale a sphere (presuming uniformly), then you have to look at the GettingStartedReceiving example script. Write a method that takes the incoming (float) value using oscIn.MapFloat() and set the localScale of the target sphere transform. You need to convert the float value to a Vector3 value, like so: transform.localScale = new Vector3( value, value, value ).

    (3). VFXGraph – should be totally possible, by writing a script. Look for examples on how to access exposed properties in VFX Graph.
     
  24. kenman

    kenman

    Joined:
    Mar 3, 2014
    Posts:
    14
    i bought the plugin and planning to do some dmx addressable led.
    I found some reference scripts using artnet to send the data:

    for example :
    data = new data[512]
    artnet.data[0] = 255

    if i want to use your plug-in, how to send the data, can you give me some example? thx so much
     
  25. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @kenman. DMX is a different protokol. It won't work. Best bet I think is to find a c# implementation and adapt it.
     
  26. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Update 2.3.2.png
    OscSimpl 2.3.2 is available!

    Minor update with bug fixes and optimisations.

    – Reduced garbage created by OscMessage.ToString() and thereby greatly improved performance of inspectors.
    – Added byte count monitoring for OscIn and OscOut.
    – Optimised internal buffer handling.
    – Fixed bug in OscMessage.RemoveAt().
    – Moved message sending from EndOfFrame to LateUpdate. To send as fast as possible, call OscOut.Send() in Update.
    – Deprecated OscOut.multicastLoopback. This feature was never working as expected because C# Socket.multicastLoopback only affects the same socket. (The plan is to reintegrate it in a future update).
     
  27. Bryan3D

    Bryan3D

    Joined:
    Feb 14, 2013
    Posts:
    22
    What I'm looking for is an OSC asset that will allow me to communicate between a Unity desktop app and a desktop DAW. I'd like to use the DAW's VST host to play high-quality VSTi sound samples on command. Kind of like how CoolSoft's Virtual MIDI Synth can intercept MIDI commands to play Soundfont sound samples. Is this possible somehow?
     
  28. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    If you are absolutely sure that your DAW can receive OSC (not MIDI) and forward it to your VST, then OscSimpl will work fine for you. OscSimpl does support MIDI over OSC, but I have yet to see a DAW that supports that natively, so first test if your DAW can route simple OSC messages to your VST.

    I did something similar back in 2007, where I experimented with using spring physics in Unity and sending collisions events as OSC a physical modeling synth in Logic.
    https://cec.dk/works/nerve/
     
  29. Bryan3D

    Bryan3D

    Joined:
    Feb 14, 2013
    Posts:
    22
    I bought MIDI Unified in 2013 and had pretty good luck with it sending MIDI notes to the CoolSoft Virtual MIDI Synth - configured to be the default Windows MIDI Player. Now, I want to see if it can send MIDI to a DAW (Band-in-a-Box, in this case) with MIDI OX acting as a go-between. I've contacted the folks at Foriero Studio to see if this approach might work so that anyone could use Unity to create a stand-alone PC/Mac app that has VST Host functionality.

    The DAW is "playing" the Kontact 6 VST Player plug-in as its MIDI Output device. And it's recognizing MIDI OX as a valid MIDI Input device. All I need now, is a way to point MIDI Unified or RtMidi to MIDI OX.

    I located a free-ware Unity project that uses RtMidi to send MIDI note messages to all MIDI Input devices it can find. It finds the CoolSoft Virtual MIDI Synth OK, but this simple script isn't finding MIDI OX (which the DAW is identifying).

    I've attached that Unity project for your perusal.
     
  30. Bryan3D

    Bryan3D

    Joined:
    Feb 14, 2013
    Posts:
    22
    Here's the file...
     

    Attached Files:

  31. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Thanks for sharing, this may be useful to others.
     
  32. Bryan3D

    Bryan3D

    Joined:
    Feb 14, 2013
    Posts:
    22
    I had success getting Unity to connect to the Kontakt 6 VST MIDI Player. I'll paste in the instructions below, but I'll also attach a Word document with photos that describes the procedure much more clearly than text only:

    The Unity Player PC/MAC build settings (for what they're worth :O)

    Architecture: x86_64
    Api Compatability Level: .NET 4.x

    Download and install the following "free" apps:

    1. "LoopBe1" MIDI I/O "virtual cable":

    https://www.nerds.de/en/download.html

    2. "RtMidi" Unity project file from GitHub:

    https://github.com/keijiro/jp.keijiro.rtmidi

    3. "Native Access" VST instrument manager from Native Instruments:

    https://www.native-instruments.com/en/support/downloads/

    4."Kontakt 6" VST Player (it will run as stand-alone, desktop app in this setup - not as a VST Instrument plug-in):

    https://www.native-instruments.com/en/products/komplete/samplers/kontakt-6-player/

    5. Select "LoopBe Internal MIDI" as the MIDI Input device on "Port A" for the Kontakt 6 Player.
    *** SEE PHOTO ***

    6. Ensure that the "Status" of the "Microsoft "GS Wavetable Synth" and the "LoopBe Internal MIDI" MIDI Outputs is set to "Off".
    *** SEE PHOTO ***

    7. Click on the "diskette" icon in the toolbar, and select "Load" from the VST file dropdown list.
    *** SEE PHOTO ***

    8. Select a VST instrument from the list (...Kontakt Factory Selection\Instruments\Band\Jazz Guitar.nki).
    *** SEE PHOTO ***

    9. Reduce the Unity app's output level (now with the label changed to "Unity3D" in the Player's track mixer) to about -30dB with the slider to avoid massive signal overload (and the resulting loud distortion) if used at the default 0dB setting.
    *** SEE PHOTO ***

    10. Set the "Unity3D" track to use "Port A [LoopBe Internal MIDI]" and "Channel 1".
    *** SEE PHOTO ***

    11. Open the "RtMidi" project in the Unity Editor.

    12. Run the RtMidi "Test" scene in the Editor's Game Player or create a PC/MAC "Test.exe" build file.

    The Test scene and the Test.exe app will both recognize the "Microsoft GS Wavetable Synth" and the "LoopBe1" as MIDI Output devices as indicated in the Console messages sent at run-time in the Editor's Game Player:
    *** SEE PHOTO ***

    The Kontakt Player will play the notes sent to it with the VST instrument(s) that are currently loaded in the Player and set to the MIDI Channel(s) that RtMidi is using for each instrument note message its sending on each channel. This is Channel 1 by default, so this is why Channel 1 was selected above.
     

    Attached Files:

  33. noel3d

    noel3d

    Joined:
    Apr 22, 2020
    Posts:
    4
    I was after was a simple set of controls to map osc data to game object . Do have to write scripts to phrase and map the data for transform/ rotate / scale or position of ? I thought it might be a an option after the transform drop down?
     
  34. meta-meta

    meta-meta

    Joined:
    May 10, 2013
    Posts:
    6
    After upgrading OscSimpl, I've encountered a problem with OscIn.Map. It looks like my listeners are being ignored when OscSimpl calls `Clean()` I have a rather unique use-case, trying to map listeners from ClojureCLR via Arcadia. I haven't confirmed yet but I suspect that this would also occur if trying to map a lambda expression in C#. Stepping through in a debugger, I noticed that your code is trying to match the first param, which in my case is a System.Runtime.CompilerServices.Closure. My second param is what your code expects as a first param.

    I went back to using an older version 1.3 where `Map` accepts a `UnityAction` as a callback whereas the latest uses a `System.Action`. Some relevant info about the Closure arg: https://stackoverflow.com/questions...ion-results-in-delegate-with-closure-argument
     
  35. stf51

    stf51

    Joined:
    Mar 25, 2021
    Posts:
    8
    hi and thks for your work ,
    i am rather new in the world of unity and scripting . I test most of your example and i am looking for a way to switch from a scene to another by sending an osc command .
    anybody as any clue on how to do this ?
    is there a list of the " handlers " we can achieve to control by your script ?

    thx a lot !
     
  36. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Hi @stf51. You will have to create your own script with a public method for OscIn to target (map to). If you understand the provided OscSimpl examples, then you just need to look at the Unity API for scene management.
     
  37. lc1990

    lc1990

    Joined:
    Jan 20, 2016
    Posts:
    2
    I have tested OSC Simpl and it is great. But why does the computer app send OSC data to the Android app after packaging, but the Android app can't receive OSC data?Android sends OSC data to PC, but it receives it
     
  38. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    So as started earlier here and in the store description, Android is not officially supported, simply because I don't own an android device, so I can't test. However, there is a good chance it will work.

    If your phone is not receiving, either it has a firewall blocking the messages, or the app on the PC is prevented from sending the messages. For the PC, you can refer to the manual section about trouble shooting, but for Android you'll have to Google a bit.

    All the best!
    Carl Emil
     
  39. lc1990

    lc1990

    Joined:
    Jan 20, 2016
    Posts:
    2
    Thank you very much.I solved the problem.The problem is not the code, but the custom systems of third-party Android vendors limit the reception of UDP broadcast functionality, so some custom Android systems can only send OSC but not receive OSC data.A simple solution would be for Android to send IP to the other end, and the other end would send data via the Android phone's IP instead of broadcasting, so Android could receive OSC data!
     
    cecarlsen likes this.
  40. jesperberger

    jesperberger

    Joined:
    Mar 30, 2020
    Posts:
    2
    Hi! Im trying to implement OSCsimpl to a project - it works fine when in editor but as soon as I enter play mode I stop receiving messages? Am I missing something?
     
  41. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    That sounds strange. Did you remember to enable "Open On Awake" or alternatively call Open() on the OscIn component in the Start or Awake method?
     
  42. jesperberger

    jesperberger

    Joined:
    Mar 30, 2020
    Posts:
    2
    Thanks for quick response. After a restart of my computer the problem doesn't persist. Strange. And thanks for great asset.
     
    cecarlsen likes this.
  43. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    23
    Hi Carl-Emil.

    Just to add - I have seen this behaviour too a handful of times - i.e. messages stop being received until after a
    reboot. Unfortunately I haven't ever been able to track down the conditions that cause it. It does seem to be a problem confined to the editor though,

    Jon
     
  44. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    Thanks for letting me know Jon. I haven't encountered this myself yet. Do let me know if you find a consistency.
     
  45. nocheapones

    nocheapones

    Joined:
    Mar 31, 2021
    Posts:
    2
    Hello, I just purchased this asset and am attempting to test the receiving functionality. Using your example above under "how to receive", I get the following compilation error: "Argument 2: cannot convert from 'method group' to 'Action<OscMessage>'" Any ideas what might be causing this problem and how I can fix it?

    Forgive me if this has been addressed already but I haven't been able to find any mention of this error in the documentation or in searching this thread.
     
  46. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    I'll have a look right away. Meanwhile ...
    - Are you using the original GettingStartedSending.cs script?
    - What Unity version and OS are you using?
     
  47. nocheapones

    nocheapones

    Joined:
    Mar 31, 2021
    Posts:
    2
    I was not using the original script, so I opened the OscTest scene in a new project and received the same compilation error. Restarted my computer, and no longer getting that error.

    It's not a problem anymore, but if you are interested, I'm using Unity version 2020.3.0f1 and Windows 10.
     
    cecarlsen likes this.
  48. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi @cecarlsen Thanks for this excellent asset, it's really simplified my workflow.

    I'm running into an issue decoding Osc messages, I've set my scene up according to the attached image and Osc messages are coming through in the Inspector, I was hoping to send them all onwards to my OscRouter which then sends XZ and Y rotation values to separate objects. The messages however are not getting through to OscRouter's RecieveOsc function- I think it could be something in the mappings? Thanks!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class OscRouter : MonoBehaviour
    6. {
    7.     public float x;
    8.     public float yRot;
    9.     public float z;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.        
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.        
    20.     }
    21.  
    22.     public List<Transform> allImageMarkers = new List<Transform>();
    23.  
    24.     public void RecieveOsc(OscMessage message)
    25.     {
    26.         Debug.Log(message.ToString());
    27.         bool whichCamera;
    28.         message.TryGet(0, out whichCamera);
    29.  
    30.         for (int i = 0; i < 12; i++)
    31.         {
    32.             string whichObject = string.Format("AR_0{0}", i);   //make a string AR_01 to AR_0012 TODO Change the Sender to just AR_1 to AR_12 etc
    33.             if (message.TryGet(1, ref whichObject))              //if the message has the string then
    34.             {
    35.                 string posX = "PosX";
    36.                 string posZ = "PosX";
    37.                 string rotY = "RotY";
    38.  
    39.                 if (message.TryGet(2, ref posX))
    40.                 {
    41.                     message.TryGet(3, out x);
    42.                 }
    43.                 if (message.TryGet(2, ref posZ))
    44.                 {
    45.                     message.TryGet(3, out z);
    46.                 }
    47.                 if (message.TryGet(2, ref rotY))
    48.                 {
    49.                     message.TryGet(3, out yRot);
    50.                 }
    51.                 Vector3 combined = new Vector3(x, yRot, z);
    52.                 SendInfoToObjects(i, combined);
    53.             }
    54.         }
    55.     }
    56.     void SendInfoToObjects(int i, Vector3 v3)
    57.     {
    58.         Vector3 position = new Vector3(v3.x, 0, v3.z);
    59.         Vector3 rotation = new Vector3(0f, v3.y, 0f);
    60.         allImageMarkers[i].position = position;
    61.         allImageMarkers[i].rotation = Quaternion.Euler(rotation);
    62.  
    63.     }
    64.    
    65. }
    66.  
     

    Attached Files:

  49. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    863
    You've set up OscIn to forward all messages to your script by adding a mapping with the address "/". So far so good.

    Then you attempt to check the address using message.TryGet(0, out whichCamera) and message.TryGet(1, ref whichObject). That however is getting argument at index 0 and 1 (so first and second argument). The message only has a single argument, and that is a float, not a boolean or a string. To read the address you need to use message.address. To check if an address contains a specific part, you can use string function message.address.Contains("Whatever").

    You proceed to call SendInfoToObjects() every time a message has been received. That is more than necessary. The values of posX, posY, posZ, rotX, rotY, and rotZ are send as individual messages with a single argument each. Instead, collect them in class variables and call SendInfoToObjects() in LateUpdate. In your case, you have AR_1 to AR_12 sources, all with unique pos and rot values, so you could use arrays. Perhaps also use a boolean flag(s) that tells whether new values have been received that frame before calling it.

    Let me know if this helps.
     
    Last edited: Jul 21, 2022
  50. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    thanks so much, that’s super helpful!