Category Archives: Unity

Stress testing Unity’s LLAPI, what are the limits?

NetTest – a tool for stress testing the LLAPI, full Unity project download at the bottom!

Seth, what the hell do you know about netcode, anyway?!

Woah, with the attitude already.  Look, I’m all about multiplayer.  Have been for a long time.  I’ve gone from being excited to get two people walking on the same ANSI map in LORD2 in the early 90s to hitting the 70,000 concurrent user mark during busy times in Growtopia.

In addition to writing my own junk, I regularly play with Unity and Unreal and am constantly trying to see how they can fit my developing style – mostly I need them because it’s becoming a losing battle to try to maintain your own 3D engine if you also want to actually design and release games too.

What’s LLAPI, anyway?

LLAPI stands for Low Level Application Programming Interface.  It’s what Unity’s HLAPI (High level) API is built on.  I guess both of those can be called part of UNet. (Unity networking)

Why not just use the HLAPI like a normal person?

That might be ok for some projects, especially round-based networked games without too many players.

When you are targeting MMO level network performance where a server may have to track stats of millions of players and simulate a world for weeks instead of minutes, the first rule is:

Stay as low level as you reasonably can. 

I don’t want someone else’s net code to even think about touching my gameobjects, I just want it to deliver reliable/unreliable packets that I write/read straight bytes to.  That’s it.  I want to handle things like prediction, dead reckoning, and variable serialization, myself!

What’s the deal with UDP, TCP, and WebSockets?

Both UDP and TCP are internet protocols built on top of IP.

TCP is a bidirectional socket based connection that insures your data is correct and sent in the right order.

It’s like calling Jeff, he picks up the phone and you can both talk until one of you puts the phone down.  Oh, and after you say something, you make sure Jeff understood you correctly each time, so that eats up a bit of time.

UDP is is a stateless connection where single packets get sent.  You write your message on a rock and throw it at Jeff’s window.  While it gets there fast, it’s possible you’ll miss and Jeff will never see it. If dozens of people are throwing rocks, he needs to examine each one carefully to figure out which pile to put it with so the text is attributed to the right thrower.  He might read the second rock you threw before the first one.

WebSockets are basically TCP with a special handshake that’s done over HTTP first.  To continue this already questionable analogy, it’s as if you had to call Jeff’s mom for permission, and then she have you his cell number to call.

In theory WebSocket performance could be similar to TCP but in practice they are much slower and unreliable, I don’t really know why but hey, that’s what we get.  I suspect this will improve later.

For games, UDP is nice because you can send some of your packets fast with no verification that it was received, and others (more important packets, like dying) with verification which sort of makes those packets work like TCP.

That said, many most games probably would be ok with a straight TCP  steam as well and having a connected state can make things easier, like easily applying SSL to everything and not worrying about unordered packets.

Why use WebSockets instead of UDP or TCP? Just use UDP or TCP for everything, moran

BECAUSE I CAN’T!  Browsers won’t allow the Unity plugin to run anymore, they just allow straight javascript/WebGL these days.  It hurts.  I mean, I wrote a cool multiplayer space taxi test for Unity using TCP sockets and now nobody can even play it.

What does LLAPI use?

It can read from both sockets (UDP) and WebSockets at the same time and route them so your game can let them play together.  But how fast is it, and does it work?

This brings us to the second rule of netcode:

Use stress tests without game code to notice glaring problems early and more clearly

Which finally brings us to the point of this post.  NetTest is a little utility I wrote that can:

  • Run as a client, server, or both
  • If you connect as “Normal client” you can all chat with eachother
  • Run with a GUI or as headless (meaning no GUI, which is what you want for a server usually)
  • Can open “Stress clients” for testing, a single instance can open 100+ clients sockets
  • When stress mode is turned on, the stress clients will each send one random sentence per second.  The server is set to re-broadcast it to ALL clients connected, so this generates a lot of traffic.  (300 stress clients cause the server to generate 90K+ packets per second for example)
  • Server can give interesting stats about packets, payload vs Unity junk % in the packets, bandwidth and server speed statistics
  • Built in telnet server, any telnet client can log on and get statistics directly or issue commands
  • Tested on Windows, linux, WebGL
  • Supports serializing variables and creating custom packet types, although the stress test only uses strings
  • Everything is setup to push performance.  Things that might mess with the readings like Unity’s packet merging or modifying values based on dropped packets is disabled.  All processing is done as fast as possible, no throttling or consideration to sleep cycles.
  • Keep in mind a real game server is going to also being doing tons of other things, this is doing almost nothing CPU wise except processing packets.  Testing things separately like this make it easier to see issues and know what the baseline is.

ABOUT TEST RESULTS

These tests are presented ‘as is’, do your own tests using my Unity project if you really want exact info and to check the settings.

My windows machine is a i7-5960X, the remote linux box is similar and hosted on a different continent, I get a 200 ping to it.

All packets in NetTest are being sent over the ‘reliable’ channel.  No tests involve p2p networking, only client<>server.

Settings:

config.AcksType = ConnectionAcksType.Acks32; //NOTE: Must match server or you'll get a CRC error on connection
config.PingTimeout = 4000; //NOTE: Must match server or you'll get a CRC error on connection
config.DisconnectTimeout = 20000; //NOTE: Must match server or you'll get a CRC error on connection
config.MaxSentMessageQueueSize = 30000; 
config.MaxCombinedReliableMessageCount = 1;
config.MaxCombinedReliableMessageSize = 100; //in bytes
config.MinUpdateTimeout = 1;
config.OverflowDropThreshold = 100;
config.NetworkDropThreshold = 100;
config.SendDelay = 0;

 

TEST 1: 300 CLIENT IDLE (LOCALHOST, WINDOWS BOX)

Ok, here I’m curious how many bytes LLAPI is going to use with clients doing nothing.

Server is set to localhost.  I’ve got 4 NetTest’s running – the one on the bottom right has had “Start local host” clicked, and the three others each have added 100 stress clients.

Results:

  • Around 30 bytes per stay alive packet per client.  (23KB total over 7.74 seconds, sent 2.2 packets per client over 8 seconds, so roughly what I would expect for the 4000 ms ping timeout setting)  Are stay alives sent over the reliable channel?  Hmm.
  • Adding and removing test clients is a blocking operation and gets progressibly slower as more are added – why does it get slower and cause my whole system to act a bit weird?
  • While closing the instances looks normal, the instances are actually spending an additional 30 seconds or so to close sockets that were opened
  • Side note: Having a client ping the host (at localhost) takes about 2 ms.  (normally this would be bad, but given that it can’t check until the next frame, then once more to get the answer, this seems to match the framerate decent enough)

I’m not going to worry about the socket slowness, this may be related to a windows 10 resource thing.  I’ll launch with less clients in future tests to help though.  The server itself has zero speed/blocking issues with actually connecting/disconnecting though, so that’s good.

 

TEST 2: 200 CLIENT STRESS (LOCALHOST SERVER, WINDOWS BOX)

Ok, now we’re getting serious.  I have 5 instances – 4 have 50 stress clients, 1 is the server.  (I could have run the server on one of the stress client instances, but meh)

First I enabled 50 clients in “stress mode” – this should generate 10,000 packets (50*200) per second.  The server gets 50 lines of text from clients, then broadcasts each one to each of the 200 clients.  Huh, stats show it only sending around 6,000 packets per second, not 10,000.  However, we can see all the lines of text are being delivered.

That seemed fine so I upped it to all 200 clients doing the stress test – this should cause the server to send 40,000 packets a second (and receive 200 from the clients).

The stats show only 24,549 packets and 5.3 MB per second being sent. About 15% is unity packet overhead, seems like a lot but ok.  Server FPS is good, slowest frame was 0.02 (20 ms) so not bad.

Is unity combining packets even though I set config.MaxCombinedReliableMessageCount = 1; ?  Oops, I bet that needs to be 0 to do no combining.

I also notice 4,346 per second packets being received by the server.  200 for my messages, and I assume the rest are part of the “reliable guarantee” protocol they are doing for UDP where the clients need to confirm they received things ok.  Oh, and UNet’s keep alives too.

In the screenshot you can see an error appearing of “An abnormal situation has occurred: the PlayerLoop internal function has been called recursively… contact customer support”.  Uhh… I don’t know what that’s about.  Did I screw up something with threads?  It didn’t happen on the server, but one of the four client instances.

I let it run at this rate for a while – a few clients were dropped by the server for no reason I could see.   Not entirely stable at these numbers I guess, but possible it would be if I ran it on multiple computers, it’s a lot of data and ports.

TEST 2: 100 CLIENTS STRESS (REMOTE SERVER, HEADLESS LINUX)

As nice as it is to be able to turn on both the server (localhost) and the client directly from the same app in the Unity editor to test stuff, eventually you’ll probably want to get serious and host the server on linux in a data center somewhere.  This test let’s us do that.

I’ve changed the destination address to the remote IP. (You can click the GameLogic object to edit them, I was too lazy to make a real GUI way))

I have a .bat file that builds the Unity project (on Windows) and copies it to the remote server, then triggers a restart.  It’s run on Linux like this:

cd ~/NetTest
chmod +x ./linux64headless
./linux64headless -batchmode -nographics -logFile log.txt

Here is a screenshot of the 100 clients (using one instance of NetTest) connecting to the linux server (which is also NetTest) (And no, that’s not the real port/ip, stop trying to hack me, Mitnick)

So let’s try to digest this data.

  • NetTest Client: The 100 clients are self reporting receiving about 1,150,000 (1.15 MB) bytes of actual payload data per second. (10000 lines of text).  Zero packets in the send queue
  • Windows system: Windows says 12.1 Mbps per second, so 1.5 MB, close enough, who knows what else I’m streaming/downloading
  • Linux system: iotop shows server sending 10.Mb (1.25 MB per second) so that seems right
  • Linux NetTest: (using telnet) it’s reporting it’s sending 1.22 MB per second (only 3,458 packets per second, yeah, definitely some packet merging happening)  The total stats went negative, I ran this a while, uh… I guess I need to be using larger numbers, probably rolled over.
  • Linux: Server is running at 1100 FPS, so zero problems with speed.  You’re probably thinking “Hey, it’s headless, what do you mean frames per second? What frames?”, ok, fine, it’s really measuring “update()’s per second”, but you know what I mean.  Slowest frame out of the 90 second sample time was 0.0137 (13 ms)
  • I don’t have it in the screenshot, but top shows the server is not too power hungry, its process seems to use 3% (no load) to 15% (spamming tons of packets).  Keep in mind we aren’t actually DOING anything game related yet, but for just the networking, that isn’t bad

I tried 200X200 (4x the total bandwidth & packets, so 5 MB a second) but the outgoing packet queue started to fill up and I started dropping connections.

TEST 3: WebGL (REMOTE SERVER, HEADLESS LINUX)

I’m not going to bother making pics and somehow this post already got way out of control, but here is what seemed to be the case when I played with this earlier:

  • No WebSocket stats are included in the stuff UNet reports – “the function called has not been supported for web sockets communication” when using things like NetworkTransport.GetOutgoingFullBytesCountForHost on it
  • WebGL/WebSockets be slow.  Real slow. If pushed the bandwidth to over 18KB per second (per Chrome tab), packets started to get backed up.  I don’t know if things are getting throttled by the browser or what.  The server eventually freaks out when the send queue gets too big and starts throwing resource errors.
  • When creating stress test clients, a single WebGL tab seems limited to 14 WebSockets max (Chrome at least)
  • I suspect there could be issues with a naughty WebSocket filling up the queue and not sending acknowledges of receives, your game probably needs to carefully monitor packets sent/received to disconnect people quick if they abuse the connection
  • WebSocket queue/etc issues don’t affect or slow down normal connections, so that’s something
  • Mixing WebSocket and normal Sockets (UDP) clients work fine, that’s a very handy thing to be able to do

Final thoughts

All in all, I think directly using LLAPI in Unity 2017.1+ is promising.  Previously, I assumed I’d need to write my own C++ server to get decent socket performance (that’s how I did the Unity multiplayer space taxi demo) but now I don’t think so, if you’re careful about C#’s memory stuff.

Issues/comments:

  • How is it ok that Unity’s text widget/scroller can only show like 100 lines of text? (65,535 vert buffer errors if you have too much text, even though most of it is off screen)  Maybe I’m doing something wrong
  • Unity’s linux builds don’t seem to cleanly shutdown if you do a pkill/sigterm. OnApplicationQuit() does not get run, this is very bad for linux servers that could restart processes for reboots or upgrades. (if it’s a dedicated server you can work around it, but still!)
  • WebGL builds can’t do GetHostAddresses() so I had to type the real IP in for it to connect (I should try switching to the experimental 4.6 net libs)
  • To my great surprise, my telnet host contined to run and send answers even after stopping the game in the editor.  How could that game object still exist?! Threads and references are confusing, I fixed it by properly closing the telnet host threads on exit.
  • The Unity linux headless build worked perfectly on my CentOS 7.4 dedicated server, didn’t have to change a single thing
  • It’s weird that you’ll get CRC errors if PingTimeout/AcksType/DisconnectTimeout don’t perfectly match on the client and server. I wonder why there is not option to just let the server set it on the client during the initial handshake as you want to be able to tweak those things easily server-side.  I guess the client could grab that data via HTTP or something before the real connect, but meh.

NetTest download

Download the NetTest Unity project with full source here

Note:  I left in my .bat files (don’t mock the lowly batch file!), thought they may be useful to somebody.  They allow you to build everything for linux/win/webl, copy to the remote servers and restart the remote server with a single click.  Nothing will work without tweaking (they assume you have ssh, rsync etc working from a dos prompt) but you could probably figure it out.

Source is released under the “do whatever, but be cool and give me an attribution if you use it in something big” license.

The Last E8 postmortem (LD39) and some Unity vs UE4 thoughts

Presenting, the crappy game title I made! Akiko’s comment was “I didn’t know you were going to show my model up close, ugh”

The Last E8 Postmortem

Last weekend was the triannual Ludumdare game jam.  If you don’t know what that is, it’s a masochistic ritual where you voluntarily force yourself to create a new game over a weekend and publish it for all to see.

Akiko pressured me into it as she wanted to Blender up some things for practice.  I acquiesced to be her programming partner if we could come up with something to match the theme.

The LD theme announced was “Running out of power”. This was 10 AM our time.

The Idea Phase

We agreed to think up some ideas and exchange them at lunch.  So in a Kyoto thai place Akiko showed me her idea:

Hmm.  I don’t know what to say about that except, I like it.  Something about being an employee who has to manage his drug use to stay productive.  (for the record, RTsoft does not endorse the use of illegal narcotics.  I do however, endorse the world’s favorite stimulant, coffee.)

As for myself, I didn’t have much except a vague concept of celebrating the Tesla Model 3’s release with a game based on it somehow.  3D flying game?

So we starting working on Akiko’s idea – resolutely requiring that we completely nail down the game mechanics in photoshop or on paper before even starting.

I figured there were two possible ways to take this:

  • Lemonade Stand style: Strategic choices made, some kind of turns system. Mostly buttons and clicks.
  • Cookie Clicker style: Also buttons and clicks, no real strategy but slowly building up your empire. (I’m playing as I write this article.  Whee!)

I was appalled to find Akiko wasn’t aware of either game. You think you know somebody.

I decided “Cocaine Clicker” was the way to go simply because I liked the name and according to google it wasn’t taken.

Side note: I always google names because if I don’t, people will think I copied something else.  I sort of miss pre-internet days where you could just be original without caring if people thought you weren’t original.

Theme problems

I did some photoshop mockups of the buttons and tried to map out some gameplay.

Unfortunately “Running out of power” didn’t really match what I’d designed; the concept of running an office, buying more employees and managing their illicit substance needs just didn’t work with it.

A fundamental problem is you never run out of anything in a classical clicker game, you only gain.

I did like her idea of a split screen, half being the office, and half being the drug farm/factory. Sort of two games in one with a symbiotic relationship between them required for survival.

Engine problems

As I mulled this over I fired up my game engine for the first time.  I decided to use UE4 as that’s what I’ve had in my head in recently for some VR tests.  (If you have a Vive, please try my tech demo later!)

Lo and behold, UE4 was cursed.  I had setup a basic C++ UE4 project but was plagued by crashes and bugs.  I mean, I hadn’t even written any real code yet.

The worst of it was the silent errors.  Sometimes something internally was broken that caused a setting to be grayed out that shouldn’t be.  I feel like the only way to be safe is basically restart the editor after every C++ class is added or a blueprint is reparented. Slow.

Those issues are WORSE than a simple crash, because until it occurs to you to restart, your progress is entirely obstructed for unknown reasons.  I thought I had done something wrong, when I hadn’t.

Knowing I probably had less than a day of total time to throw at this, I said screw it and used this jam as a chance to try out Unity 2017.  (I’d used Unity 5 last year but forgot everything)

I have to admit, Unity is nice.  The MS Visual Studio 2017 integration is fantastic these days. Zero crashes.  Breakpoint debugging worked immediately with no hoops to hop. Goodbye forever, MonoDevelop.

I’m constantly switching back and forth between these two engines (plus my own homegrown one for 2D and simple 3D)  so I’m going to pause for a second and show my current engine scorecard in this middleware battle royale.

Seth’s Unity VS UE4 scorecard:

Unreal Engine 4:

  • Allows real C++ so the last twenty years of code doesn’t feel wasted
  • Actually using that C++ causes editor glitches non-stop and longish compile times
  • I think it’s faster overall and easier for me to replace the networking code with my own
  • I don’t like the royalty scheme.  Being legally required to calculate royalties for eternity (assuming your game makes anything) is awful
  • Blueprints may seem ok at first, but they are actually the spawn of satan as soon as you need to do anything slightly tricky.  Go ahead, write Vector3 vFinal = (vDir +vOffset).Normalize()*speed*dragMod); in BP, see what a mess that looks like. Now cut and paste it into a new entity and get forced to recreate and reconnect all the variables involved.
  • Forced to choose between overly simplistic BP or slow compiling C++
  • HTML5 support is questionable, doesn’t seem to be a priority.  Huge file sizes, rendering problems
  • Full source code.  Makes this a good choice if you’re going to be implementing your own streaming landscape or enet networking.

Unity:

  • No C++.  C# isn’t bad, but I miss my direct pointer manipulation and huge library of code I’ve written, so it means a lot of porting, or using plugins that are less portable.
  • Compile times are a dream
  • No crashes, was 100% stable (so far, anyway)
  • Better 3D import options, it can handle .blend files directly
  • Better audio import options too, unlike UE4 it can properly handle a simple .mp3 file
  • Excellent HTML5 support – nearly a must for a public game jam, more on this later
  • Month to month licensing isn’t cheap for the Pro version, but at least they don’t have their hooks on your game royalties for eternity.  Free version isn’t bad either really
  • No source code (well, not for peons like me, anyway)

So in the end, I’m thinking I’m around 5X faster when using Unity simply because of faster compiling and smarter import options.  I guess I need to do a VR demo in Unity and test that side of things too though.

Screw it, let’s use Unity

In the end I told Akiko, look, I’m switching engines so how about I do a sort of simple 2D flying game as a refresher for me.

“Can I still make 3D models in blender?”

“Sure!”

“Ok, I’m in.  What will the game be like?”

“It will be like The Last V8 crossed with Space Taxi”

“Never heard of those”

The Last V8:

Space Taxi:

Using Unity’s auto collision

I remembered this trick from when I made Multiplayer Space Taxi a while ago, you can very easily add collision to a level simply from an image.

Unity’s magical Polygon Collider 2D component

About HTML5 vs native with game jams

Because this is my main development machine, long gone are the days where I can run unsigned binaries from people I don’t know.  I know, I hate that, but unless I setup a clean or virtual machine that’s just how it is.

Play our game

So finally, here is the game we made.  True to its heritage, it’s extremely hard.  Good luck!

Play the game in your desktop browser here

Unity project/source code here

(also, the LDJAM site link for it is here)

Dev Diary: A look at Visual Studio 2013, Unity, and UnityVS

oldman

I’m a bitter old man

When you’ve been making stuff as long as I have you get comfortable with your tools.

I am a greased ninja with Visual Studio 2005, VisualAssist, and C++.

I’m a snail drenched in chunky peanut butter working with anything else.

But yesterday I gave Visual Studio 2013 + Unity a shot and it actually wasn’t half bad, so here are my tips if that’s something you’re interested in.  Beats MonoDevelop by a mile as far as I can tell.

My tips for people upgrading from old VS versions:

  • First I downloaded Visual Studio 2013.   I guess it’s “Ultimate” and free for 90 days?  Fine.  After that we’ll see, but I’m pretty sure I’m not going to cough up $13,299 for Ultimate!
  • Set keys to the included VS 2005 layout.  Changed it so F7 will compile all.
  • MOST IMPORTANT: Enabled Options->Environment->Tabs and Windows->Floating tab wells always stay on top of the main window.  Without this I found VS 2013 totally unusable.
  • Turned off the silly all upper case menu fonts
  • Installed Productivity Power Tools 2013 (adds some stuff to make the IDE smarter, sort of like VisualAssist?)
  • Oh God, what are these vertical lines connecting every matching brace?!  Disabled that, FAST.
  • Stopped it from showing “References”
  • Turned off its funky new scroll bars, but ended up turning them on again, gotta see how that feels, they do have some interesting data
  • Installed UnityVS (MS did something very smart, they bought it and made it free)
  • Imported the “Visual Studio 2013 Tools.unitypackage” into a simple Unity project (this file gets installed by UnityVS  into C:\Program Files (x86)\Microsoft Visual Studio Tools for Unity\2013 or something, have to dig for it)
  • Inside Unity I double clicked a source code file and viola, it did load the project in VS 2013!  It wouldn’t start the Unity project when I hit F5, but it did connect to the process, so after manually starting the game in Unity it did perform debugging fine.  I think Visual Studio has THE BEST debugger around so this should come in handy.  Er, I mean, I’m guessing, since my code never has bugs of course. <awkward silence and then someone coughs in the back>
  • When you hit a breakpoint, the Unity editor side seems to completely freeze until you hit Resume, too bad, seems like it would be useful to tool around in there and look at objects during debugging.
  • Anyway, everything works and doesn’t feel half bad.  So far.  I assume the crashing,  freezing, and constant reboots that also plagued my experience with MonoDevelop/Unity will start soon though.

Anyway, here’s a picture of what debugging looks like.  I think it would be handy to be able to write non-Unity specific C# code and simultaneously have Unity and non-Unity VS projects open using it, maybe C++ as well as I still like that for my server backend code.  (See my Space Taxi Multiplayer test)  (Uhh, ignore that code in the screenshot, it’s uh, an exercise for the reader to figure out how to make that less stupid looking and redundant)

unity_and_visual_studio

 

Adventures in Unity3d 1: A simple event scheduling system and sound manager

Forget the cloth physics, kid

So I’m learning Unity and figured it couldn’t hurt to blog about my experiences while still fresh.

After doing a few of the sexy terrain and physics tutorials which instantly let me do amazing things with a few clicks, I realized I probably couldn’t even write tic tac toe.

OH YEAH?!  Be amazed:

Fine, it sucks.  But that wasn’t the point, it forced me to come to grips with how objects, scripting and using classes together all worked in Unity and C#.

(And yes, the enemy “ai” is actually Board.GetRandomEmptyCell() … busted! )

Source is here as a zip.  (Requires Unity 4.3, despite the intense graphics it doesn’t require pro)

A common trait of programmer-centric devs is are constantly thinking about projects on a “shared” and “app specific” level.  They are organizing code into two places, with the more generic stuff meant to be reused.  We just can’t help it!  It’s why we always end up with engines and middleware.

So in case it’s useful to anybody else, here are some general utilities I wrote and an explanation of why they are useful.

You can download them as a unity package here:  rt.unitypackage (they are also in the tic tac toe source above)

RTAudioManager

I didn’t see a simple way to play a “crap.wav” filename from script (you have to create an object and attach a sound and ..) , so this is a very basic class that takes care of stuff like that.

You add an audio file under Assets/Resources (uncheck 3d sound source on the file in Unity – That one confused me, as there is no error, you just don’t hear anything…) and can play it from anywhere like this:

//don't add the .wav or .mp3 at the end, it's automatic
RTAudioManager.Get().Play("scream");

Or to get fancier:

//Play at 1.0f volume and a pitch mod of 2 (twice as fast)
RTAudioManager.Get().PlayEx("scream", 1.0f, 2.0f);

To play a song (will kill any current song playing)

//plays mysong.ogg or mp3 etc at 1.0f volume and 1.0f pitch mod, looping
RTAudioManager.Get().PlayMusic("mysong", 1.0f, 1.0f, true);

To set it up in a project is easy, just add RTAudioManager.cs to an empty GameObject somewhere.  (It will rename the gameobject RTAudioManager if it isn’t already)  It uses a singleton style .Get() to give the same instance to everybody.

RTEventManager

One of the first things I do in a new programming environment is figure out how to call any function in N seconds with any number of parms .

Even in the crappy Tic Tac Toe above, the difference between everything happening at once and instead using subtle delays (for instance, a delay before the AI moves) makes a huge difference.

If interesting timing is simple to add and tweak in your game, you’re much more like to do it, if you’re as lazy as I am.

Coroutines and other schedulers I found didn’t quite fit my requirements.. plus, I like to waste time re-inventing everything anyway!

Same as RTAudioManager, to set it up you just add it to an empty GameObject in your scene.  There is no other setup needed to just start using it.

It uses SendMessage internally and things it sends to must have a unique GameObject name.

Let’s say you want to use the above RTAudioManager to play “pain”(.wav) in 1 second instead of instantly.  No need to build a special timer, just use RTEventManager like this:

//schedule the function "Play" to be called in one second, sending a string variable to it.
RTEventManager.Get().Schedule(RTAudioManager.GetName(), "Play", 1.0f, "pain");

It’s a little ugly, but not too bad to understand.  The .GetName() is just a function I added to the RTAudioManager class to make it easy to get the GameObject name its attached to, but a string of “RTAudioManager” would have worked just as well, you just have to be sure you know what stuff is named.

Want to call a function called Respawn that is in an attached script on your player GameObject (which is named “Player”) in 5 seconds with no parms?

//note that you don't have to send that extra parm
RTEventManager.Get().Schedule("Player", "Respawn", 5.0);

But what about RTAudioManager.Get().PlayEx(“fileName”, 1.0f, 2.0f);  from above? What if we want that to happen in 5 seconds?  That needs three parms, how can we schedule that?

Well, I couldn’t figure out a great way, but because the scheduler’s single parm can be of any object type we can work around the problem.  One way would be to send a custom class, but I’m far too lazy to be creating classes everywhere so here’s what I came up with instead:

//will play in 5 seconds
RTEventManager.Get().Schedule(RTAudioManager.GetName(),
   "PlayEx",  5.0f, new RTDB("fileName", "scream",
   "volume", 1.0f, "pitch", 2.0f));

What’s going on here?  RTDB is a simple database key/value (which can be any object type) system that can be created and sent inline with a flexible number of parms.  Key “fileName” is a string, key “volume” is a float and so on.

Unfortunately, when doing this, the receiving end must expect what is coming and know the keyname(s) to extract the data.  RTAudioManager’s code to receive it looks like this:

public void PlayEx(RTDB db)
{
PlayEx(db.GetString("fileName"),</pre>
db.GetFloatWithDefault("volume", 1.0f),
 db.GetFloatWithDefault("pitch", 1.0f)
 );
 }

It’s just a front end for calling the real function.  It will warn if sent the wrong type.  If a parm is left out, it will use a default value so it still works. (filename is the only thing absolutely required)

On the bright side, you can easily add support for more parameters without breaking backwards compatibility in places you’ve already used it.

Speed considerations

Now, you may be worried about the costs of using SendMessage internally, the name lookups, and inline initializing and usage of RTDB and the like.  Well, unless you’re sending 25+ messages a second I wouldn’t worry about it.  It’s mostly for controlling program flow and timing, if you’re sending 1000 messages a frame (for instance, trying to control a sprites x/y animation with it)  it’s definitely the wrong tool for the job.

One click build and upload

Oh, also included in the zip above is a windows .bat file that builds and uploads the web version of the game.  You’d have to edit it a bit, but here it is:

call app_info_setup.bat
REM get our ftp logon info
call d:\projects\SetFTPLogonInfoTanked.bat

:Actually do the unity build
rmdir build\web /S /Q
mkdir build\web

echo Building project...
%UNITY_EXE% -quit -batchmode -buildWebPlayer build/web .
echo Finished building.

rmdir temp /S /Q
mkdir temp
mkdir temp\%FILENAME%

xcopy build\web temp\%FILENAME%\ /E /F /Y

rename temp\%FILENAME%\web.html index.html

if not exist temp\%FILENAME%\index.html beeper.exe /p
if not exist temp\%FILENAME%\web.unity3d beeper.exe /p

ncftpput -u %_FTP_USER_% -p %_FTP_PASS_% -R %_FTP_SITE_% /www/ temp\*

echo File uploaded:  http://www.%_FTP_SITE_%/%FILENAME%

:Let's go ahead an open a browser to test it
start http://www.%_FTP_SITE_%/%FILENAME%
pause

It requires ncftp to be installed.

Oh, app_info_setup.bat sets the app name, but it also would need to setup the ftp site and password data. Basically you need this somewhere, could even cut and paste it to the top of the .bat:

SET FILENAME=breakout
SET UNITY_EXE=A:\pro\Unity\Unity.exe
SET _FTP_SITE_=mydomainname.com
SET _FTP_USER_=username
SET _FTP_PASS_=mypassword

Breakout test

To get slightly more graphical, here’s a “throwaway breakout” I whipped up (using the old 3d physics, not the new box2d stuff)  (Maximize to look slightly less ass, use arrow keys to control):

Was watching the Unite keynote (woah, Richard Garriott!)  and believe I heard that 10% of all downloads happening on iOS are now Unity based.  That’s just.. wow.

Why Unity and C#?  Aren’t you that hardcore C++ guy who made Proton SDK?

Yeah, but that doesn’t mean I have to use C++ for everything.  I still use Proton (ahem, Growtopia) and it’s my go-to weapon if I have to port an existing C++ product to mobile. (as with Dink Smallwood)

But let’s face it, supporting the newer graphic technologies on the plethora of platforms and graphics chips out there is a losing battle for a one-person developer.  Especially if I’d like to actually make games too.

(Note: Others are still adding new features such as GLES2 support  to Proton in separate distributions, which is fine with me)