Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: kyy921 on February 13, 2012, 12:05:48 AM

Title: Can playmaker support OSC? like touchosc?
Post by: kyy921 on February 13, 2012, 12:05:48 AM
some times I wanne control my game in a wifi environment , I like to use touchosc  http://hexler.net/software/touchosc , it can control like vj  vvvv, Can playmaker make some action to connect playmaker with osc?? 
Title: Re: Can playmaker support OSC? like touchosc?
Post by: kyy921 on February 13, 2012, 12:08:29 AM
http://uscript.net/forum/viewtopic.php?f=21&t=1089  uscript have some thing like this
Title: Re: Can playmaker support OSC? like touchosc?
Post by: jeanfabre on February 13, 2012, 01:27:23 AM
Hi,

 Since PLaymaker use c# for each of its actions, it is possible to implement custom actions to support OSC messages.

 I haven't seen any such action on the forum yet tho. But you can definitely write some. I looked a some of the code involved to work with OSC and it looks completely feasible.

 I have unfortunatly no time to play around with this. If you can't get anywhere, and no one stepped in with some custom actions. Just post on this thread again when playmaker will be out of beta.

 Bye,

 Jean
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 18, 2012, 03:45:35 PM
I would be very happy to see OSC done properly in PlayMaker. Im not really good enough at programming to do this stuff nicely yet. I have managed to tie PlayMaker together with incoming OSC messages using one of the existing Unity OSC scripts, but my method is very basic. I am simply using a script to detect specific OSC messages and use floats or booleans from OSC to set the values of specific Playmaker variables. I can then use PlayMaker logic to check for these values changing, and use the values to control other things using PlayMaker actions in the normal way. But I still have to go into my script file and code all of the OSC messages I want to listen for, and tell it what FSM & variable to target. A proper solution would enable you to do all of that within PlayMaker, and could even feature a learn mode so the PlayMaker action could be told what OSC message to use by listening to incoming OSC messages in edit mode rather than the user having to type in the OSC message manually. Im not sure we'd need support for every possible variable type that OSC can send, floats and booleans would probably be enough for most uses, although the ability to handle OSC messages that contain more than one variable would be useful (e.g. a message like /xypad/1/ 123.4 13.1 )

If an additional incentive for someone to write this is required then I would be prepared to put up a bounty of around £100 for a nice solution, but I've no idea if this will be enough to encourage someone to do this.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 18, 2012, 04:03:37 PM
Actually having now seen how easy it was for someone to get it working with uscript Im probably going to have a little attempt at doing it properly myself now. First version is likely to be limited in some key ways but should still be a useful start. Wish me luck and I'll post later if I get anywhere :)
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 18, 2012, 04:09:14 PM
Oh and by the way, to get the most out of OSC on something like the iPad I recommend the Lemur app rather than touchosc. Its not a cheap iOS app but its got plenty of features and is certainly cheap compared to the Jazzmutant Lemur OSC hardware version of a few years ago.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 19, 2012, 11:59:43 AM
I got it working :D

My approach so far involves having a GameObject with three scripts attached to it. The only thing the user needs to do with these scripts is to set the port variable on one of them to the port that you want to listen to OSC messages on.

Then in PlayMaker I have created an action where you set a string to the OSC Address Pattern you want that Action to work with (e.g. /slider1 ), and when a matching OSC message arrives its value will be used to set a FSM float variable. This will happen for as long as that state is active. A FSM event is triggered when a message is received, so you can move to another state as soon as a message with a matching address pattern is received if you want to.

It seems to work quite well. I can have as many of these OSC Actions active as I want, listening to many different OSC messages and updating many variables continuously or as triggers to change state. Limitations at this point, which I probably won't get round to fixing myself at the moment, are:

It will only listen to one port (but this is fairly normal for OSC apps)
A game object with scripts on is also required rather than being a pure PlayMaker solution (a purer way would involve moving more script code to another PlayMaker action that you would use just once to start the OSC port listening stuff)
You have to be careful not to have more than one active OSC Action listening for the same OSC Address Pattern at once (its fine to have more than one action within a single FSM listening for the same OSC Address Pattern, so long as they are not both active at the same time, e.g. if they are attached to different states. But if you were listening for the same Address Pattern in several different FSMs where both actions could be active at the same time, there will probably be problems with my system).

Anyway my initial test OSC Action only uses the first OSC message value, and treats it as a float, so I should probably try to add a bit more functionality to this before sharing it. But I will still try to post it later today :)

Title: Re: Can playmaker support OSC? like touchosc?
Post by: kyy921 on February 28, 2012, 12:59:18 PM
hope to see your action :)
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 29, 2012, 02:43:23 PM
Sorry for the delay, I got distracted by other things and I tend to need to motivation of others responding to get me to keep going!

I'm not sure when I will get the time to polish this thing as much as I would really like, so I'll probably end up sharing it in a less than completed state, as its better than nothing and won't take much work by someone else to improve if necessary.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 29, 2012, 04:30:12 PM
OK here is the unpolished version. I post it here for someone to check before drawing more attention to it, in case someone knows a way to quickly make it better or spots some other issue. All the detail I gave in my post from a while ago still applies, i.e. the major flaw in this version is that you can only listen for a particular OSC address pattern (such as /slider1 or slider/1/) in one active state at a time. This flaw will not matter for some scenarios, but is a pain in other situations and probably breaks part of the ethos of PlayMaker. The simplest way to avoid getting into trouble due to this issue is to stick to the following rule:

Keep your listening for a specific address pattern to a single FSM. You can have it on multiple states within that FSM, just not different FSMS where more than one of the states listening for a particular address may be active at once.

So it would be fine to have a FSM listening for /slider1 and another FSM listening for /slider2
It would be fine to have multiple states within a single FSM listening for /slider1
But do not have 2 different FSMs both listening for /slider1 or /slider2 or anything else.

Another way to put this:

If you want to have more than one FSM making use of the same incoming OSC value, create a single FSM that deals with the OSC and stores it into global PlayMaker variables, then access those from your other FSMs.

Also please note that so far I have only made actions that capture either 1 or 3 float values from an OSC message. Non-floats and different quantity of values will require new PlayMaker Actions, but most of these will be very easy to make by looking at my float examples.

With that disclaimer out of the way, I will post the files shortly.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 29, 2012, 04:53:48 PM
EDIT - Please see page two of this thread for a newer version of all files except UDPPacketIO.cs which hasn't changed since this post was first written.

Files should be attached.

Put Osc.cs and UDPPacketIO.cs files into your /Plugins folder (create this folder if it doesn't already exist in your project).

Put PMOSC.cs into your /Scripts folder (again create this folder if it does not already exist in your project)

You may be able to put the above files somewhere else if you prefer, but script compilation order issues may arise so be aware of that stuff before putting these files elsewhere.

Put GetOscFloat.cs and GetOscVector3 into your PlayMaker/Actions folder.

Create an Empty GameObject in your scene and call it OSC
Attach Osc.cs, UDPPacketIO.cs and PMOSC.cs scripts to this game object
Set the port that you would like to listen to OSC messages on by changing the 'Listener Port' variable of the PMOSC Script using the unity inspector.
If you like, drag the OSC GameObject to the Project Window to create a prefab for future use in other scenes.

Now in a playmaker FSM, add to a state one of the new actions that you will find in the Action Browser in the 'OpenSoundControl' section.
Choose a FSM variable that will store the OSC message float value
Type in the Osc Message Address that you want to listen for (for example /1/fader1)
You do not need to specify an Osc Game Object unless you called yours something other than OSC
If you want to move to a different state as soon as a matching OSC message is received, select an event to trigger in the 'Osc Message Event' section.

Tip: If you are wanting to process a continual fast stream of changing OSC values related to a specific message address, don't change state every time a message is received. Rather, do something with the resulting FSM float variable in the same state as the OSC listener state is attached to. e.g. follow the above instructions, make sure you have created a float variable in your FSM and told the OSC Action to use it, and then add another action to the same state which will affect a game object in unity in some way. e.g. don't set a 'Osc message event', add a 'Set Position' action below the Get Osc Float action, and tell it to use your variable to change the X position of a game object.

I probably made everything sound more complicated than it really is by trying to explain it thoroughly, but there you go. The main OSC scripts are attached to this post, the PlayMaker actions themselves will follow very shortly.

EDIT - most attachments removed as newer versions are available in a later post
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 29, 2012, 05:02:01 PM
Here is the Action for receiving a single float from an OSC message. I haven't tested the one that captures 3 floats from a message yet, so I won't post that straight away.

EDIT - attachment removed as a newer version is available in a later post
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on February 29, 2012, 05:59:55 PM
OK managed to find a device I could use to spit out OSC messages that have three floats so that I could test this action, and it seems to work so here it is:

(for reference I used a 3DConnexion SpaceNagivator device with OSCulator software to test this)

This particular action turns OSC message that have 3 float values into a PlayMaker Vector3 variable but it would be trivial to store them as 3 separate floats if thats what you wanted.

EDIT - attachment removed as a newer version is available in a later post
Title: Re: Can playmaker support OSC? like touchosc?
Post by: kyy921 on March 01, 2012, 09:38:09 AM
It works well! great!!! thank you elbows!!!
Title: Re: Can playmaker support OSC? like touchosc?
Post by: kyy921 on March 01, 2012, 10:04:38 AM
if you take 2 get osc float in the same fsm seen have some problem, have you try control something with the xy-pad mode ? using vector3??
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on March 01, 2012, 04:42:47 PM
OK I think your problem is because I only provided example Actions which could picked OSC messages which have either 1 or 3 float values, and you need one that receives 2 float values in a message.

The attached action should do what you want, I just tested it with the xy-pad in touchosc.

With this one you need to create 2 PlayMaker Float variables and tell the Get Osc Two Floats Action to use one for the 'Store First Result' and the other for 'Store Second Result'.

EDIT - attachment removed as a newer version is available in a later post
Title: Re: Can playmaker support OSC? like touchosc?
Post by: kyy921 on March 02, 2012, 05:03:30 AM
yeah! the new 2float actions works very well, :)
another problem is when you switch to another tab, and the control with the unity3d will break
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on March 02, 2012, 10:30:36 AM
Sorry about that. My code in PMOSC.cs that attempts to show you the last OSC Message Address & Values received was not very good, it did not like receiving OSC messages that had no value.

Please replace PMOSC.cs with the attached version which works properly.

Also note that when you don't need to see the incoming OSC Message Addresses & Values for debugging purposes, you should untick 'Debug Osc Messages' option in PMOSC for a slight increase in performance.

I should do the same checks inside the Actions really, will fix this soon, for now you are OK as long as you make sure to always pick an Action that listens for the same number of values in a particular OSC message as are actually being sent.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: elbows on March 02, 2012, 02:13:25 PM
OK I really hated the fact that my implementation only allowed a particular OSC Message Address to be listened to by one PlayMaker Action simultaneously, this isn't foolproof enough. So I messed around with the Osc.cs code and managed to work around this issue, now you can listen for a particular OSC Message Address (e.g. /1/fader1) as many times as you like simultaneously in different Playmaker FSMs and it should work. Yay, thats a better fit for PlayMaker :) Requires more testing really but I will post it here, simply replace the files in your project with the ones attached to this post.

Also updated the Actions so that they check to make sure the right number of values came with the message they are receiving. Now if less values came through than the Action is designed to handle, the Action will not do anything with that message. If more values are received than they are designed to handle, then they use the ones they are designed to handle and ignore the rest.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: Drakon on May 30, 2012, 07:03:06 AM
Hi Guys,

Will this set up work on the iOS per chance? I'd like to control Ableton live with it. Naturally, I'm not a C# coder. What would be the reality of getting this functionality together? Any advice much appreciated.

Drakon
Title: Re: Can playmaker support OSC? like touchosc?
Post by: rmd on April 10, 2013, 05:13:46 AM
hey,

thanks for your implementation!
i tried to set it up, getting 3 floats from VDMX5 (lo, mid, hi) to unity over OSC.
the correct values show up in the debug section of the PMOSC.cs,
but the playmaker actions (get osc float) don't seem to be able to get the values.
(i'm on unity4 and pm 1.5.3)
any ideas? thanks.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: eduardomarques on May 08, 2013, 01:10:54 AM
This looks amazing. I'd love to get osc data in Unity.
I'm having trouble getting it to work though. Apparently no data is coming through. I'm sending data from processing to unity (a float) but i'm not getting any data in unity...
Has anyone tested it on the latest version of unity?
Title: Re: Can playmaker support OSC? like touchosc?
Post by: bicycler on May 09, 2013, 11:52:40 AM
hey there, I also get the same problem, the correct values show up in the debug section of the PMOSC.sc, but nothing in the "get osc float", anybody can help? thanks


hey,

thanks for your implementation!
i tried to set it up, getting 3 floats from VDMX5 (lo, mid, hi) to unity over OSC.
the correct values show up in the debug section of the PMOSC.cs,
but the playmaker actions (get osc float) don't seem to be able to get the values.
(i'm on unity4 and pm 1.5.3)
any ideas? thanks.
Title: Re: Can playmaker support OSC? like touchosc?
Post by: Drakon on May 23, 2013, 11:19:41 AM
Can't wait to try it out! Any youtube clips of it  connecting with an Daw like Reaktor or VJ apps - Touch FTE, Max/Msp?
Title: Re: Can playmaker support OSC? like touchosc?
Post by: trashtrash on September 28, 2014, 09:34:16 PM
Hi could someone help me I was using this system for a year with no problems but then I upgraded unity now whenever I try to get OSC in unity is give me NullReferenceException: Object reference not set to an instance of an object....please help I really need this to work soon
Title: Re: Can playmaker support OSC? like touchosc?
Post by: henrygordon on November 01, 2014, 09:17:16 PM
Did you ever tried reverting the OCS to its default or remove it first and have it install again with the new update built-in? I have learned that after doing same idea from the games I am doing at http://www.igamesforgirls.com/cartoon (http://www.igamesforgirls.com/cartoon).
Title: Re: Can playmaker support OSC? like touchosc?
Post by: Ubik3D on November 26, 2017, 04:12:53 PM
I try to use the OSC scripts with 2017.2. It works in editor, but in build mode it does not recieve any OSC.

Can anyone help?

I get this error message in the editor:
Quote
ThreadAbortExceptionSystem.Net.Sockets.SocketException: The descriptor is not a socket
  at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint& remote_end, Boolean throwOnError, System.Int32& error) [0x00000] in <filename unknown>:0
  at System.Net.Sockets.Socket.ReceiveFrom_nochecks (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint& remote_end) [0x00000] in <filename unknown>:0
  at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x00000] in <filename unknown>:0
  at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00000] in <filename unknown>:0
  at UDPPacketIO.ReceivePacket (System.Byte[] buffer) [0x0003e] in /Users/Daniel/Atelje/Programmering/Unity Projekt/Unity 2017/2017-OSC-PLAYMAKER-FUNNEL/2017-OSC/Assets/Plugins/UDPPacketIO.cs:129
  at Osc.Read () [0x0001a] in /Users/Daniel/Atelje/Programmering/Unity Projekt/Unity 2017/2017-OSC-PLAYMAKER-FUNNEL/2017-OSC/Assets/Plugins/Osc.cs:210
UnityEngine.Debug:Log(Object)
Osc:Read() (at Assets/Plugins/Osc.cs:239)
Title: Re: Can playmaker support OSC? like touchosc?
Post by: jeanfabre on December 01, 2017, 01:39:30 AM
Hi,

 unfortunatly, It's not PlayMaker related and I have no experience with OSC myself, have you askled on Unity forum?

 Bye,

 Jean
Title: Re: Can playmaker support OSC? like touchosc?
Post by: Ghettokon on June 13, 2022, 12:11:14 PM
Hi Jean and all

Let's get this OSC library on ECO System! This is a 10 year-old thread, we need this!

Hi,

 unfortunatly, It's not PlayMaker related and I have no experience with OSC myself, have you askled on Unity forum?

 Bye,

 Jean
Title: Re: Can playmaker support OSC? like touchosc?
Post by: wetcircuit on June 13, 2022, 12:48:59 PM
extOSC has Playmaker actions on github:

https://github.com/Iam1337/extOSC.PlayMaker