Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have downloaded the JSONObject plugin for parsing JSON in Unity but when I use it in a script I get an error indicating JSONObject cannot be found. My question is how do I use a custom object class defined inside another class. I know I need a using directive to solve this but I am not sure of the path to these custom objects I have imported. They are in the root project folder inside JSONObject folder and class is called JSONObject.

Thanks

share|improve this question

3 Answers 3

Assuming that you're using C#, there are two steps to include a third party DLL in your Unity project (these steps may be different for Unityscript or Boo).

First, you'll need to include the DLL in the root directory of your project. Next, you'll need to include the "using" directive (ie: the "using" keyword, followed by the namespace in which JSONObject is defined) at the top of any source code files which use the JSONObject library.

I'm not sure which JSON library you're using, but I've had a great experience with LitJSON. It's very easy to use, and very lightweight. I've experimented with a number of other C# JSON libraries, but many of them have dependencies on unsupported .NET libraries, or are very complex or bloated.

share|improve this answer

This is just a clarification on John's answer - the way we got it to work and a slight extension for maintenance.

First of all, right-click in Project view in Unity, pick "Import new asset". Navigate to your DLL and add it. You can organise it as necessary (e.g. putting it in a "Libraries" folder).

Then exactly as John said, use the using directive.

Now if/when you get an updated library (in our case it's one of our own libraries so it's constantly updating), you can copy it over the top of the existing one. This also means if you're building the library yourself, you can set the output location in Visual Studio for that project to be /yourunityproject/assets/libs.

share|improve this answer

You have to put the JSONObject files in the folder "assets/plugins". Then you can access it from your UnityScript code without using a directive.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.