Skip to main content
50 votes
Accepted

Use an instance or a class for game resources (wood,iron,gold)

Go with the second approach, simply due to the fact that you can introduce new resource types or items at any time without having to rewrite or update code (data driven development). Edit: To ...
Mario's user avatar
  • 8,497
30 votes

Use an instance or a class for game resources (wood,iron,gold)

A rule of thumb is that you use different classes when objects require different code and instances of the same class when the objects only require different values. When the resources have different ...
Philipp's user avatar
  • 120k
14 votes

Use an instance or a class for game resources (wood,iron,gold)

I would like to add there are two extra options: Interface: you can consider it if the resource class would be just a "storage" for 5 integers and each other entity would have different logic ...
wondra's user avatar
  • 4,930
8 votes
Accepted

Unity Json utility does not serialize DateTime

The problem with JsonUtility, is that it doesn't save properties, just public fields and fields with the [SerializeField] attribute. You can solve this with another class and some conversion magic, ...
lilotop's user avatar
  • 604
7 votes

unity JsonUtility.ToJson returns empty string

Unity do not serialize properties. You need to have simple fields in order to serialize class. It is one of the limitation of jsonUtility. In Short, Use ...
machineman's user avatar
6 votes

How to store condition dependent item information in JSON

I wouldn't do this based on item name. Instead, I'd implement a system of modifiers to describe what an item does, something like... ...
DMGregory's user avatar
  • 135k
5 votes

unity JsonUtility.ToJson returns empty string

if I recall correctly, when you serialize a C# class to JSON, it serializes members, not properties (even if by {get; set;} the compiler creates the members). You can try by marking the members as ...
LifGwaethrakindo's user avatar
5 votes
Accepted

Unity - How to create a game-save with a preview image?

Since you're working with JSON format already, you could simply include the preview image as a Base64 blob that can be decoded on the fly when reading the savegame list. Assuming you have access to a ...
liggiorgio's user avatar
  • 4,866
4 votes

Unable to remove class information in serialized json file using libgdx

to remove class information, use fileJson.setTypeName(null) to display all infomation including default value (in your case "false" is default of boolean), use fileJson.setUsePrototypes(false); see ...
NathanBui's user avatar
4 votes
Accepted

UPDATED: Deserialise Nested JSON with JSON Utility Unity 5.4

Your JSON firstly is faulty and secondly does not match the data model. To break down your JSON: ...
BackFromExile's user avatar
4 votes

LibGDX Json writes only part of class

Well I fixed my issue that I was having. Instead of using libGDX Json to write to file from the class I used JSONObject and used put() and surrounded it with try and catch to write the ...
Finnrir's user avatar
  • 63
3 votes
Accepted

Communicate Unity application via a series of Json

https://docs.unity3d.com/Manual/JSONSerialization.html The documentation has very detailed explaination. In your case the classes/structures (that store data ) should look like: ...
tc07's user avatar
  • 455
3 votes
Accepted

Could not find a part of the path "/jar:file:/data/app

It won't find the path because Android has a different path when it comes to streaming assets. Your code won't work, whereas the below will: ...
TheGinxx009's user avatar
3 votes

Updating Json files in a Unity game - What am I doing wrong?

JSON is a string-based format. When you change the length of something in a JSON file (for example by changing "CurrentHP": 99 to ...
Philipp's user avatar
  • 120k
3 votes

Why can't I read this JSON file?

com.badlogic.gdx.utils.GdxRuntimeException: File not found: skin\glassy-ui.json (Classpath) The json reader can't find your file, you can't fix that by changing the files content. The first problem ...
VaTTeRGeR's user avatar
  • 776
3 votes

Is there a way to hardcode a JSON file into a Unity build?

Let's assume somewhere in your code you do something like this to open the external JSON file, read its text, and parse it into a structured Dialogue object ...
DMGregory's user avatar
  • 135k
2 votes

Use an instance or a class for game resources (wood,iron,gold)

You should use option 1, which has 3 advantages: It's easier to instantiate a resource - instead of having to pass the type of the resource as a parameter, you would just do, for example, ...
Zac's user avatar
  • 121
2 votes
Accepted

Deserialise Nested JSON with JSON Utility Unity 5.4

You say you want to use data.series.points[0].ts but then you... don't, you use data.series.points.get_Item[0].ts The thing you ...
Elva's user avatar
  • 3,223
2 votes
Accepted

Implementing modular game control with JSON/etc. config file?

This is the keyboard input method that I have been using in javascript. First define the keyboard function, which I have shamelessly copied from somewhere (I'm ...
Jay's user avatar
  • 810
2 votes

Relational Databases vs XML vs public static finals: Pros and Cons

1: TOTAL overhead. Like driving a 40 ton truck to your weekly shopping for you and your spouse. Adds a lot of memory eating high end functionality into what is essentially a configuration file. If you ...
TomTom's user avatar
  • 155
2 votes

Parse JSON in Unity

It will simply done with JsonUtility.FromJson<JsonClass>(jsonString) Use [Serializable] before each class for ...
Md. Shafiur Rahman's user avatar
2 votes
Accepted

Error: "JSON must represent an object type" when parsing array of objects

When you write a line like this: LineData line1 = JsonUtility.FromJson<LineData>(Dialog_Data.text); You're saying "the JSON in this text string represents ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

unity JsonUtility.ToJson returns empty string

Unity's JsonUtility only serializes public fields. ...
Tony's user avatar
  • 46
2 votes

Unity3D - JsonUtility returns empty string

JSONUtility can serialize fields, but it can not serialize properties. As the documentation of [SerializeField] says: The serialization system can do the ...
Philipp's user avatar
  • 120k
2 votes

Json Libgdx serialize / de-serialize a Object Map of Object Maps

libGDX Json converts Enums to strings and therefore cannot serialize / de-serialize Map keys to anything but strings. To fix this, either... Use strings for keys in Maps (ObjectMap, HashMap ect.). ...
Macmanmatty's user avatar
2 votes
Accepted

Where should I put a JSON file to be readable in a Unity build?

If the file is modified at edit time, and not modified in the built version of the game, just put the file somewhere in your Assets directory like you do with other assets including textures, models, ...
DMGregory's user avatar
  • 135k
2 votes
Accepted

How to store localized text data in Unity?

Unity has built-in support for storing localization data. Import the localization package from Unity's package manager, and check out the Quick Start Guide. It supports localization for ...
Evorlor's user avatar
  • 5,803
1 vote
Accepted

Invalid character '' in input string at LitJson.Lexer.NextToken ()

What you need to do here is that in your ...
TheGinxx009's user avatar
1 vote

Binding Nested JSON To Dictionary Not Working

Currently Unity 5's JSON utility is not fully capable of doing all the neat tricks you might expect. For instance, it can't do an array of objects that contain other arrays. You can hack the json ...
Tartle Wizard's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible