Unity & Visual Scripting « Mutant Sparrow

Unity & Visual Scripting

It’s no secret that I’ve been dabbling with Unity lately, but as I tried to improve my productivity, I discovered a pretty handy package.

Until now, I was merely scripting with unity. With a hint of JS, you can actually go great length in Unity, but as a designer, I find myself pretty often working too slow.
I’m no JS guru for starters, but I also need to more or less browse the entire Unity documentation to find a method that might suit my actual need. It’s not a bad thing, but it’s time consuming, and while I actually appreciate to learn things the Right Way, I don’t have that much time to spare atm.

So I began to explore different ways to get an increase in efficiency, and that’s how I stumbled on playMaker from Hutong Games. playMaker is a nifty little middleware that’s basically a visual scripting tool build around the concept of Finite-State Machine.
You create little boxes with logic events in it, and link them together. When stuff happen, events are thrown and the machine navigates in your boxes, executing whatever’s in it. It’s more complicated to explain than to use, really.

Let’s pick an example:

I want a sound to happen when you press a button.
I beging by creating an object in Unity, select it and go to the playMaker UI. There, I create a new starting state, because well, I have to start somewhere. I name it ‘IDLE‘.
In it, I create a GUIButton, to be able to click on it. My button says “Play“. It’s really simple as playMaker has a wizard that helps you pick all possible actions among a list, and there’s a huge lot of them. Really, really handy.

First State.

I also create an Event called ‘go_Play‘, which is the actual event that will be fired when I hit the Play button. I attach the event go_Play to the IDLE state, because that’s when there’s no sound that you want to play a sound, and I link the button to the event. In other words: when I press the button, I trigger the go_Play event.

I add the exiting event.

Now I simply create a new state I call “PLAYING“, because that’s what we’re doing here. I attach a ‘Play Sound‘ action to it, so I actually play my sound clip. I simply drag and drop my sound from the library on it. I also link a ‘Finished‘ event to the state, in order to have a way to handle things when my sound is done playing.

So now I got 2 boxes, and then what? Simple enough dear friends! I click and drag from the go_Play event and lo & behold! An arrow appears that I can link to any other box. So I link go_Play to PLAYING, and the Finished event on PLAYING back to IDLE.

…And link the boxes. Tada!

And… that’s it. Zero line of code, under a minute and voilà: A button on screen. I press Play, the sound plays, and everything works fine.

Honestly, This thing’s a beauty.
playMaker has a lot of built-in actions and functions, but even better, interfaces pretty easily with any standard Unity component, most other plugins I tried, and can fire or be fired from your JS or C# code.

At runtime, playMaker also behaves beautifully: you can follow the flow of your actions in the diagram, highlighted in real time. It logs what’s happening if you so wish, with a nice colored log, and explains errors clearly, and there’s a lot of error catching to help you going.

Linked the wrong state? playMaker sees that. Created the wrong type of variable for the action? playMaker tells you the right type you should have. Also of note is that the playMaker UI is really fine and easy to get into.

I really think that this kind of visual scripting should be standard in Unity as it’s, like, seriously awesome.

That’s all that’s needed to handle character movement in a platformer. With colors!

If you’re not the hardcore coder type and using Unity, you should really give playMaker a try: it’s great to use, flexible, well documented, has great support and decently priced (around $90, got it half price w/ Unite 2012 Special Sale).
Oh, Hell, even if you’re a hardcore coder you should give playMaker a try. It’s almost 100% assured to speed a whole lot of the more mundane tasks, and will most likely interface gracefully with your existing codebase.

Just my 2 coppers.

Leave a Reply

You must be logged in to post a comment.