Wednesday, August 29, 2012

Really Really Easy Multithreading in Unity3D.

When you start working with threads in your Unity3D project, you will discover that many things need to be done in the main loop. For example, if you try and do a Physics.Raycast call from a thread, you'll come across this error.

INTERNAL_CALL_Internal_RaycastTest  can only be called from the main thread.

This can be really frustrating, so, what to do? We need some Magic Threads!

The below example shows how the latest version of UnityExtender allows you to make a coroutine jump back and forth between a background thread and the foreground main loop. It doesn't get much easier than this, and it integrates perfectly with Unity coroutines. This new version of UnityExtender should be available in a few days.

    void Start () {
    IEnumerator ThisIsAMagicalThread() {

        Debug.Log("I am running in the background.");
        //This will raise an error
        Physics.Raycast(new Ray(, Vector3.forward));

        yield return new ForegroundTask();
        Debug.Log("I am now running in the Unity main loop.");
        //This will work!
        Physics.Raycast(new Ray(, Vector3.forward));
        yield return new WaitForSeconds(2);

        Debug.Log("About to re-enter the background...");
        yield return new BackgroundTask();
        Debug.Log("I am running in the background again.");


Tuesday, August 28, 2012

Unity3D + is one of these new fangled web services things aimed to reduce the amount of work us developers need to do to get large scale applications and games up and running. In a sentence, it's a big pub-sub service that uses Web Sockets.

I've made a Unity3D API for it, and it's available on GitHub.

Friday, August 17, 2012

The Secret Project

This is the complete schema for my current project. Of course, deliberately downscaled so you can't exactly see what is going on... :-)

I'm building most of the game server within PostgreSQL itself, using the plpython extension language. The game interface will be HTML, with a tiny bit of Unity3D visualisation. Having been out of the web dev game for some years now, I'm not sure of the best tech for exposing my database as a Web API, and I'm double unsure about what client side tech to use. Shouldn't we have a one click develop and deploy solution by now? :-)

Sunday, August 05, 2012

Controlling an IP Camera from Unity3D.

I recently bought an IP camera, which I discovered has a HTTP interface which lets me pan, tilt, take pictures etc. Of course, I had to use this from within Unity, so I wrote a small class which lets me stream the camera's image down into a Texture2D instance.

Code available on github.

Friday, August 03, 2012

Augmented Reality #2

This time, a stadium and city scape on my lounge room floor. Therei s actually a game playing in that stadium... but you can't see it from here.

Popular Posts