Code Monkey home page Code Monkey logo

unityosc's Introduction

UnityOSC v1.2.

Open Sound Control classes and API for the Unity 3d game engine

Based on Bespoke Open Sound Control Library by Paul Varcholik ([email protected]). Licensed under MIT license.

THIS REPOSITORY AND PROJECT IS NO LONGER SUPPORTED OR MAINTAINED. After 10 years, I've decided not to continue with its development

Please consider the following alternatives (more modern and better) for using OSC in Unity:

How to use UnityOSC

Install

Copy the src/Editor folder contents to the corresponding Editor/ folder of your Unity project. The rest can go to your e.g. Assets/ folder of the same project.

Usage

There are two different approaches to use the plugin:

OSCHandler

The first and original approach works by modifying and initializing the OSCHandler. It is a Singleton handling your client & server connections and sending & receiving OSC data. Additionally, all incoming and outgoing messages are logged and can be viewed in an Editor Window.

Check the documentation below for more detailed instructions.

OSCReceiver

The second approach is a simple OSCReceiver which only supports receiving OSC data but with the benefits of reduced complexity and a thread-safe OSCMessage queue.

After opening a server connection by OSCReceiver.Open(int port) you can easily receive new OSCMessages via OSCReceiver.getNextMessage(). Always make sure there are OSCMessages available by using OSCReceiver.hasWaitingMessages() before trying to receive new ones.

Documentation and examples of usage

docs/doxygen/html/index.html

docs/UnityOSC_manual.pdf

docs/UnityOSC & TouchOSC Integration.pdf

Please head to the tests/ folder for examples of usage and a TouchOSC test Unity project.

TODO

07.11 Change string concatenations to C# string builders.

unityosc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityosc's Issues

Doesn't work on UWP (HoloLens)

I'm trying to build UWP Application using UnityOSC to run on the Hololens.
However, I'm getting the error:

The type or namespace name 'UdpClient' could not be found (are you missing a using directive or an assembly reference?)

According to HoloLens Developer forum.
UdpClient has also been renamed to DatagramSocket.

see in under the forum
https://forums.hololens.com/discussion/604/udpclient-could-not-be-found
http://forums.hololens.com/discussion/578/hololens-udp-server

if I 'll be able have a time .fix this issue for me.

Receiving from external IP

Hi Jorge,

first, great work! Helped me a lot. I came across one strange issue. Receiving from another device (in the local network) does not work properly. Wireshark and another application (vvvv) I was testing with showed the UDP/OSC packages correctly but Unity did not react at all. Forwarding the received packets (again with vvvv) to another port works in Unity, so is there a difference in receiving remote and local packets?

I know that this does not necessarily need to have do with the UnityOSC package itself but perhaps you also experienced such an issue? Or is actually the port number 5555 reserved for something else in Unity?

Thank you so much!

Get an OscBundle

Hey there. How do I get several Adresses and Values from an OSC Bundle when I receive OSC in Unity? I dont get that to work. Thank you very much in advance

David

Timing Problem/Question (Packet loss?)

Hi,

I send a lot of OSC packets to UnityOSC. And the current packet was more and more in the past.
So I looked a bit in the code and I found that every 10ms a new packet is received. So I guess that's the limit for receiving packets. Next thing I noticed is that _lastReceivedPacket is just overridden in the Receive() function. So when the logs are updated in the UpdateLogs() function, it takes the last one but this happens maybe every 16ms (60fps) if you call I call it in my Update() function, so there could be packet loss right?

So I thought it would be maybe be a good idea to give the developers also an option to have access to the PacketReceivedEvent. Just to try that out I replaced the void OnPacketReceived(OSCServer server, OSCPacket packet) with

public delegate void OSCPacketReceived(OSCServer server, OSCPacket packet);
public static event OSCPacketReceived OnOSCPacketReceived;

void OnPacketReceived(OSCServer server, OSCPacket packet)
{
    if(OnOSCPacketReceived != null){
        OnOSCPacketReceived(server, packet);
    }
}

Then I could do something like this in my script:
OSCHandler.OnOSCPacketReceived += OnPacketReceived;
I then figured out that this runs in another thread which makes sense, so I can't directly change gameobjects. So there needs some kind of copying step before, so I looked how this is solved in UnityOSC and the _lastReceivedPacket is just written and read without any locking. Couldn't there be any problems with writing and reading at the same here?

LastPacket always null?

i am using unityosc together with faceosc. i have included this for testing in the update loop:

void Update () {
OSCHandler.Instance.UpdateLogs();
foreach(String entry in OSCHandler.Instance.Servers["FaceOSC"].log) {
Debug.Log(entry);
}
}

the server is running, i can see that both with netstat and in the oschelper window.

but i never get any data. there are no packets coming in. if i do the same setup with osculator instead of unityosc i can see all the data coming in and also with netcat i could dump the data coming in from faceosc on the correct port.

am i missing something?

Can't receive multibyte characters?

I have tried to receive multibyte character, I can't receive it, and it displays "???".

For example, I send "こんにちわ", it is Japanese Character, it displays "???" in UnityOSC.

Is there a good way to fix it?

impossible to tell if you have received a new message

I'm not sure I understand the design of this library. Every other OSC lib I've used gets rid of old messages as you read them out. Even when I clear a ServerLog.log, the messages somehow come back.

I can't check to see if a OSCPacket is new because the TimeStamp on them is always 0.

Not working on Android

Apology for the brevity but it was just a simple test from the example files.
When receiving transmission from the iOS it works just fine but from Android it doesn't work.

Can't debug Data from Log.

Hello,

Thanks for this library. I'm facing an issue. Currently I'm working in an app that reads data from Emotiv Epoc, I'm using this this snippet from previous examples:

    foreach(KeyValuePair<string, ServerLog> item in servers){
        // If we have received at least one packet,
        // show the last received from the log in the Debug console
        if(item.Value.log.Count > 0) 
        {
            int lastPacketIndex = item.Value.packets.Count - 1;

            UnityEngine.Debug.Log(String.Format("SERVER: {0} ADDRESS: {1} VALUE 0: {2}", 
                                                item.Key, // Server name
                                                item.Value.packets[lastPacketIndex].Address, // OSC address
                                                item.Value.packets[lastPacketIndex].Data[0].ToString())); //First data value
        }
    }

But I'm getting:

   SERVER: AndroidPhone ADDRESS: #bundle VALUE 0: UnityOSC.OSCMessage

So, I'm getting the type, not the data received. I tried unpacking the message with with no luck

I'm using Unity 5.0 and I don't know if this is the problem.

Thanks.

OSCHandler GameObjects continue instantiating without being destroyed

The plugin implemented in my own project works perfectly fine, connects and sends data out (in my case to Pure Data) without any problem whatsoever.

The only issue is that in test mode I noticed that the OSCHandler GameObjects start piling up without never being destroyed. In fact, even diving in the scripts there is nothing that destroys the GameObjects.

Is it a known issue, or am I implementing it in the wrong way?

Not working if OSCHelper isn't opened > Standalone not possible

Hi,
you're lib is really good, but the need of the OSCHelper window being opened to get it working makes it absolutely not functionnal.
In my setup, when i click play, nothing is received until the osc helper window is opened, no matter where.
When i export the application and launch it, nothing is received (i guess this is the same problem)

Is there a way to avoid this behaviour i've not seen ?

Thanks
Ben

Comparing OSC Message

Hi,

I've been trying for the last few days to use the SimpleReceiverScript to receive and compare values from the OpenVibe. I have no problems getting and even seeing the values in the console, but how do I construct an If statement to do something supposing say the incoming value is lower than something specified by me?
Unfortunately, I am fairly new to coding, and am unable to piece together what is required.
Your help is appreciated.
Thanks.

Client Doesn't Exist

Hi, I get this issue every time I run my game in Unity
Debug.LogError(string.Format("Can't send OSC messages to {0}. Client doesn't exist.", clientId));
Any help?

Thank you

Dictionary vlaues cleanup

Helo there jorge,
firstly i would like to thank you for your plugin in. its really great.

however, i have encountered, probably, a dictionary-memory problem. I am sending OSC to unity from a program in processing, and what I want to do, is sending data every some milliseconds. The problem i have at the moment is that unity stops receiving after some point. I am currently sending 45 floats each time, and it stops after 25 receptions. My intelligent guess is that the dictionary gets filled up.

So, because I am not very familiar with the dictionary structure I would like to ask you how I could empty the dictionary received values.
I've tried some things, but all I can do is delete the server completely ;p

thank you in advance
c.

Assets/OSCHandler.cs(96,23): error CS0619: UnityEngine.Network' is obsolete

Upon opening TestScene.unity in the assets folder of the tests/touchosc_integration Unity project and copying the contents of src into the Assets folder of the project, I see the following error in the console:

Assets/OSCHandler.cs(96,23): error CS0619: `UnityEngine.Network' is obsolete: `The legacy networking system has been removed in Unity 2018.2. Use Unity Multiplayer and NetworkIdentity instead.'

How to "message.add"?

Sorry this isn't an issue i just don't find a way to send múltiple data on a single OSCmessage.
I need to send Time.time, and XYZ coordenates on the same líne to ensure no lost messages fuckups.

Thanks

Send / Receive extended ASCII strings

Hi Jorge!
Thank you for your work, it helped me a lot understanding OSC.
I have one question I cannot find a solution over the Internet. I haven't seen explicitly that it is not possible sending extended ASCII characters in strings.
Nevertheless, I can't do that. Whenever I try to, I get the "?" character.
I know it's maybe not related to your plugin specifically, but any help would be much appreciated since I can't find any info even in the OSC web.

¡Muchas gracias!

MIDI

Hi Jorge, this is an amazing plugin! I'm trying to send MIDI OVer Wifi Using OSC, rom an application in Unity to Resolume Arena 6.

I didn't have any problem sending OSC address to Resolume, but now I'm wondering how to send it to resolume using TouchOSC Bridge, I test TouchOSC Bridge using the TouchOSC app on android, and it sends MIDI, now I'm wondeering how to it, using your library, it will really helpful for me, can you give me an insight? Thank you so much.

Too big latency when Recieving high rate OSC message.

Hello, I recieve high rate osc message(120 messages / per second, or higher) with big latency.
Maybe problem is here.

private void ReceivePool()
{
    while( true )
    {
        Receive();
        Thread.Sleep(10); // maybe problem here
    }
}

I suggest sleeptime parameterization.

osc bundles

Any timeline for getting osc bundles happening? I'd really like to connect open frameworks to unity via osc

Client doesn't exist

Hi, everything was ok until at some point, I've built the game and then I started getting the "Client doesn't exist" error. I am using

OSCHandler.Instance.Init();
OSCHandler.Instance.CreateClient("myClient", IPAddress.Parse(outIP), outPort);

inside the Start function of a OSCController class (very similar to OscControl example provided) and I haven't changed anything specific about it. I wrapped the SendMessageToClient in a new method

public void sendOsc(int val)
    {
        OSCHandler.Instance.SendMessageToClient("myClient", "/1/fader1", val);
    }

This is the full error

Can't send OSC messages to myClient. Client doesn't exist.
UnityEngine.Debug:LogError(Object)
OSCHandler:SendMessageToClient(String, String, List`1) (at Assets/OSCHandler.cs:287)
OSCHandler:SendMessageToClient(String, String, Int32) (at Assets/OSCHandler.cs:238)
OSCController:sendOsc(Int32) (at Assets/OSCController.cs:85)
ScreenR:Start() (at Assets/ScreenR.cs:34)

suggestions about where should I look? Thanks

Performance issues

I'm using Unity 2017.1.1 with the latest version of UnityOSC from github. The profiler reports 1,4ms execution time and 72KB GC allocation on my script, which I can trace back to the OSCHandler.Instance.SendMessageToClient() call. The function is being called three times per frame as I'm sending three parameter values out via OSC. See the screenshot for profiler details:
grafik

Unfortunately, having two instances of the script running in a scene doubles both, execution time and GC alloc, so this doesn't scale well. What can be done about this? Is this the expected behaviour or am I doing something wrong?

System is Win10x64 with an i5-3380M.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.