JSON De/Serialization Using Unity and JsonFx

Difficulty: Medium

My previous JSON tutorial was a while ago, and it never covered actually deserializing data (but is still useful on it’s own), so rather than doing the second half on its own, this tutorial will cover all the steps from the beginning using  JsonFx.

∗ This guide is tested as of Unity 4.3.4f

 

Purpose

The purpose of serializing data is so that it can be stored or shared across different systems, or even applications. It creates a common data template that can be converted back and forth (serialized and deserialized) even when the source data is not one that is understood by the receiving system or application natively. There are various common formats that can be used (i.e XML, CSV,  Binary, or in our case, JSON), to serialize data into.

In our example, we’re going to create a class that lives within our application; a Sandwich. When we create an instance of it, it will exist in memory until we destroy it or the app is stopped. Once we turn off play mode in the unity editor (or close our window in a build), that data is gone. By serializing it, in this case to a text file using JSON, not only can we store it to the file system, but we can edit it offline and see the changes reflected in our application when we load it up again. This is all sort of odd-sounding without seeing it in action, so let’s get to it.

Read More!

New Blog Look and Content

Been a long time since I updated this blog.

I’m still trying to decide exactly what I could fill it with that would be of any value to ya’ll. More info coming soon.

Read More!

Unity and JSON – Quick Guide

I’m not a big fan of XML. It’s a bit heavy and dense, and though it’s effective, I just prefer JSON.

Introduction

But what IS Json? Well I’m not going to cover that, but some people smarter than I have already answered that question, so have a look over here and come back when you’re done.

If you’ve never used it, it may take a while to wrap your head around the inception-like dictionary-within-a-dictionary structure. But after you serialize and deserialize some data, you’ll get an idea of how it works.

Unity doesn’t have a built in solution for JSON. Though Unity supports JavaScript, it’s not quite the  same flavor you may have run across in web programming, it’s actually a different language, which is why more and more people are calling it UnityScript, instead. Why do I bring this up? Well, we can’t just use existing JavaScript libraries to incorporate JSON. There are alternatives, though! Let’s explore…

Read More!

Visual Studio 2012 Surprises!

The Visual Studio 2012 product site is garbage. It’s hard to navigate, doesn’t give you meaningful information and doesn’t really boast about some of the coolest new features.

I use VS2012 when I’m developing on Windows because it’s awesome. Most of my work is in Unity, so I have it set as the default editor, so when I open scripts in Unity, they open in VS2012 by default.

A few days ago, I happened to double click an .fbx file on accident, and I was surprised to see the VS2012 loading screen popup. I figured it would open the FBX as a text file, and that would be that, but it was much more interesting than that.

Read More!

More PlayMaker Tips

PLAYMAKER TIPS

It’s easy to mistake PlayMaker for a visual scripting tool a la Kismet or uScript, but it is much, much more than that. In fact, I can see a visual scripting tool being used hand in hand with PlayMaker. PM is a tool to help you create state machines. It encourages you to develop games using a slightly different mentality–use states for everything! Of course, it’s not feasible to put all the weight on PM, but there are specific scenarios in which it shines. For example, handling input! Here are some quick tips to get the most out of PlayMaker: 

Read More!

PlayMaker and NavMesh

Either I’m blind, or PlayMaker doesn’t come with an Action for the Unity NavMesh feature.

In either case, it’s only a few lines of code, which you can find below.

The only thing you may want to change, depending on how you’re using the action, is whether or not to include the  Finish() method in there. This will exit the state if you have the transition set up, and you may or may not want to do that.

Here is the code:

Read More!