How to Set up a Unity3D Master Server on Amazon EC2

Hi everyone!

I want to write a short guide on getting a Unity Master Server set up on Amazon Web Services (AWS) on an EC2 Micro Instance. Firstly, Amazon Web Services are free for the first year as long as you are using a one micro instance (5GB image). As long as you do not have unassigned Static IPs or multiple instances running, you should not incur any charges. To get more information on what defines the free-tier you can go here: Amazon AWS Free. Let’s get started!

  1. Create an Amazon AWS Account
  2. Go to the EC2 Instances page by clicking “EC2” then when that loads, in the lefthand navigation going to instances.
  3. Click the blue “Launch Instance” button
  4. Create a new Redhat Enterprise Linux Instance under the free tier in the preconfigured AMI’s
  5. After you select it, it should ask about what instance type you like. This is where you skip this step and click on step 5, “Tag Instance.” You will see that an entry already exists, Name. You can go ahead and set the value for that to Unity Master Server for your convenience.
  6. Go ahead and click on step 6: “Configure Security Group”. We need to configure the instance so that we can access the URL. The easiest way to do this is to open the instance on all ports on TCP and UDP. You will see that the instance is open on port 22 for SSH access, now we need to click the Add Rule button and add access via ALL TCP to anywhere on the IP and same with UDP
  7. You do not need to configure anymore options. You can click the blue Review and Launch button then once you’ve review the details, go ahead and launch the Instance.
  8. You should be prompted to create a security key pair or use an existing one. This is VERY important. Do not lose the file you download when/if you create a new key pair! It is imperative that you download this .pem file to a secure location. If you don’t have it, there is no way that you will be able to access your VM.
  9. Ensure that it’s running by checking it’s status in the Instances page. If the instance state is not running, you may select it, right click, and command it to start with “Start” in the “Actions” section
  10. Now that the instance is created, we need to give it a public IP Address. Go to Elastic IPs under Networking and Security in the lefthand panel and create a new elastic IP. After you create this IP is VERY IMPORTANT that it is assigned to a RUNNING EC2 Instance. If you create an Elastic IP that is unassigned you are billed $0.005 every hour until it’s assigned. To assign it, just select it, then right click and go to “Associate Address”
  11. OK. we have a public IP for our instance, and it should be running. Good. We need to set up a way to SSH into the VM and starting messing around with the files. The best thing to do is to download PuTTY and install it
  12. Open PuTTYGen and then open your download .pem file in it (by selecting *.* All Files in the load file dialog). You can then go ahead and hit generate to create a ppk for the key file. You can put a password on it if you like. Just remember this password for later you will need to enter that in the putty console when you connect.
  13. Once that is complete you may open PuTTY and get your public DNS and place that in the Hostname box on the Sessions dialog.
  14. Before attempting to connect we need to navigate to the Connection section on the left and add our ppk into an SSH authorization section as you can see below:
  15. Now go back to the sessions page and you can save this configuration by putting a name like “Master Server” in the box below the “Saved Sessions” text and then then hitting the Save button.
  16. You should be able to connect without a snag. You will be prompted with a user account to log in with. If you type “root” it will tell you the correct user for that vm which could be something like: ec2-user.
  17. Once you’ve logged in you can go ahead and download the Unity Master Server using wget:
  18. You need to unzip the file.
  19. Then build it:
  20. You can then run it:
  21. Then you’re done!


I hope you learned something in this tutorial and if you have any problems, just comment and I’ll do my best to help you!


Easy C# Custom XML Serialization

Hi everyone,

In the past, I spent time working with XML serialization for Grey: The Lost Technology, and I ended up writing a blog post about my findings and experience with “compressing” data to create smaller xml files, which is seen here: Grey Dev Diary: Problems of Storing Maps.

Now I want to show you a specific method that I use when writing a custom serializer for an object that needs special processing during (de)serialization. First, you would implement the ISerializable interface, and you would need to implement the following functions:

public System.Xml.Schema.XmlSchema GetSchema()
    return null;

public void ReadXml(XmlReader reader)

public void WriteXml(XmlWriter writer)

For me, reading the XML had always been the hardest part, until I came up with this:

public void ReadXml(XmlReader reader)
    while (reader.Read())
        if (reader.IsStartElement())
            switch (reader.Name)
                case "Name":
                    Name = reader.ReadElementContentAsString();
                case "ValueA" :
                    ValueA = reader.ReadElementContentAsInt();
                case "ValueB" :
                    ValueB = reader.ReadElementContentAsInt();
                case "DeeperObject":
                    //If object has more information and is its own class, deserialize that one.
                    DeepObjectInstance = (ObjectTypeClass)new XmlSerializer(typeof(ObjectTypeClass)).Deserialize(reader);
                    //Do something if no case for the start element

    //Any sort of post processing

The main idea is that you loop through the start element of each entry, and then if you have a case for it, read the values. It’s super simple, and if you need to scale the object you’ve been serializing you won’t break anything.

Writing the XML is just as simple, but you don’t need to loop through anything to do it.

public void WriteXml(XmlWriter writer)
    writer.WriteElementString("Name", Name);
    writer.WriteElementString("ValueA", ValueA.ToString());
    writer.WriteElementString("ValueB", ValueB.ToString());

    //Don't forget you can call the WriteXML of another object and serialize it in the
    //same file as the one you're already writing to. It just means more processing later.
    //OtherObject.WriteXml(ref writer);

    new XmlSerializer(DeeperObjectInstance.GetType()).Serialize(writer, DeeperObjectInstance);

That’s all I have for you! If you have any questions, don’t hesitate to comment!

Understanding C# 2D XNA HLSL – Part 2

Read the first part here

I know a lot of you loved the first part of this breakdown, and now I’m back to continue the explaining!

Breakdown of Effect Parameter

Continuing from the end of the first part: What the effect parameter does here is that it takes our effect and then applies it to all of the textures that you draw then on. This is effective for coloration effects such as black and white, or inverting colors, but if you have an effect that works based on certain coordinates or is constricted similarly, then you need to be  very careful! To avoid issues like that, there is a rather simple solution when you want to apply an aforementioned size/position constricted effect to the screen.

Further Implementation

Adjusting the Effect parameter of the SpriteBatch.Begin() function is not the only way to use HLSL effects in your projects. Another method that you can do is draw all of your textures to one RenderTarget2D (Think of this as an empty texture, or a blank canvas). After you’ve drawn all your textures to that, it’s really easy to apply your effect to “the screen”.

RenderTarget2D MainTexture;

//In the Initialize function set up the rendertarget:
PresentationParameters pp = GraphicsDevice.PresentationParameters;
MainTexture = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);

        //Then create a function to draw your game textures to, and draw it all up       

        private void DrawGame(GameTime gameTime)


            spriteBatch.Draw(bg, GraphicsDevice.Viewport.Bounds, Color.White);
            spriteBatch.Draw(player, new Vector2(200, 300), new Rectangle(0, 0, 128, 128), Color.White);



        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)


            // Use Immediate mode and our effect to draw the scene again, using our pixel shader.
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            mainEffect.CurrentTechnique.Passes[0].Apply(); // for every pass that you have you can apply
                                                           // all them to the texture if you want.
            spriteBatch.Draw(MainTexture, Vector2.Zero, Color.White);



Alternatively, you can use the effect parameter in the spriteBatch.Begin() function when drawing MainTexture, because remember: The effect is applied to the texture in every Draw() function call. If you only have to draw one texture and want all the passes applied when drawn, then you can use the Effect parameter.

Why do this?

In a project I was working on I really wanted to have an INFINITE amount of 2D lights in my game, and after countless attempts at getting a high number lights (higher than 5) from all HLSL effects, I found that by drawing a my lights to a texture, and then my game to another, I could then use an HLSL effect to blend my lights together.


I hope this helped.


Flash Tutorial #2 – The Basics of Actionscript 3.0

Hey there. I just finished up another tutorial about the basics of Actionscript 3.0 (AS3). The video is about 36 minutes long and covers a wide range of topics, including: variables, conditionals, operators, functions, events, and other general basic ideas in Actionscript 3.0 (and many other languages). By the way, I talk about all those pretty much in that order, slipping in little bits of data about other things as I progress through the video.

I also finally got around to submitting SpaceFlyer online, so the project page is now updated with a playable link to the game, or you can click here. I’ll be straight about this game, it isn’t really pretty, and it doesn’t exactly have a great story line, BUT there are some sweet mechanics!

Hope you enjoy them both

Video Tutorial #1 – The Basics of Flash CS4

Flash LogoThe Basics of Flash

In this awesome tutorial, I cover the basics of Flash  CS4, I mean, the BASICS. This is probably as simple as it gets for you,  so, don’t count on other tutorials being this simple.


SO, this is the future of my website. I will probably be doing tutorials for… the rest of my life. I feel like I made a real connection here.

Nah. But I will be making more tutorials in the future that will cover Actionscript 3.0 ideas in Adobe Flash as well as other programming languages, such as C# (for XNA), and C++.