4
votes
Accepted
ScriptableObjects lose references/stored objects upon build/restarting the Unity Editor?
It was due to having auto properties on serialized classes:
public TileData TileData
{
get;
private set;
}
Using properties with ...
3
votes
Accepted
How to reference nameof private serialized field in unity custom inspector
Use your interface
Handily enough, you already have your answer. Leave the speed field public, but never pass around or declare references to that class. Only ever ...
3
votes
Update dependent values of Serializable C# classes on Inspector
You can use a MonoBehaviour or ScriptableObject's OnValidate() method. This gets called in the Editor when a script instance gets (re)loaded or when Inspector properties are changed.
It won't ...
3
votes
Accepted
Serialization/Deserialization Solutions for Loading & Playing Audio Files
Unity internally uses ogg vorbis for audio - whenever you drop an mp3 into your Unity project, the editor converts it to vorbis and uses that. Importantly, this means Unity can natively decode ogg ...
2
votes
Unitys [SerializeField] and parallel inheritance
It looks to me like you might actually want an IItem interface, or abstract class, a bit like this:
...
2
votes
How can I create a custom PropertyDrawer for my Point struct?
I tried using the solution in the accepted answer but was having some issues with it, particularly when it was being used within a list. After messing around with things a bit and trying out different ...
2
votes
Update dependent values of Serializable C# classes on Inspector
In my opinion I these variables should be treated separately. Use your properties methods as just interactor to that one variable alone. Putting logic in them is a bit smelly I think.
The setter for ...
2
votes
Accepted
Saving and loading a GameObject's full state easily in Unity3D?
I think that you went down the wrong rabbit hole and should take a step back instead of going deeper.
You goal is to generate levels proceduraly. For that you want predesigned rooms containing ...
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.).
...
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 ...
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 ...
2
votes
Component instance reference in Unreal Engine 4
To do this in Unreal C++, inside the CPP file you need to do the following:
Make sure to include the header component:
#include "Camera/CameraComponent.h"
Then in the class constructor:
...
2
votes
How to prevent Unity from generating unnecessary changes after saving a scene with no actual changes
EDIT: This bug seems to have been fixed in newer versions of Unity (e.g. 2020 LTS and 2021 LTS).
EDIT 2: This bug has returned in Unity 2022 and Unity 6
As far as I know, this is caused by a bug or ...
2
votes
Accepted
Serializing nested ScriptableObjects with runtime changes
IIRC Unity won't serialize a List where the data type is abstract.
Your FilesystemDirectory class has one field:
...
2
votes
Accepted
What is the difference between Serializable, and System.Serializable?
Unless I'm mistaken, there is no difference - System.Serializable is just the fully qualified name of Serializable.
C# has this ...
2
votes
Accepted
Text Only Dungeon Crawler game. Hardcoding Maps vs Generating Map Data externally?
I would recommend to use a standard markup format like XML, YAML or JSON for your files. There are plenty of C++ libraries available for each of them which make converting between text files and C++ ...
2
votes
Accepted
Serialize List of References
The Problem
In Unity's Docs :
[Serialize] Referenced values cannot be shared between UnityEngine.Object instances. For example, two MonoBehaviours cannot share an object that is serialized by ...
2
votes
Accepted
How to check if a Vector3 or Quaternion are unassigned?
If a struct type has not been given any particular value, it will usually default to a special value helpfully called default. (...
2
votes
Loading game state before first save has occurred (chicken/egg problem)
The file system can fail beyond your control.
If you have a default file, it might be removed due to fortuitous reasons.
That might suggest to you that to check if the file exists is the way to go. ...
2
votes
Loading game state before first save has occurred (chicken/egg problem)
I made very good experiences with keeping savegames in JSON format. The reason is that you can easily view savegames for troubleshooting and manually create and edit savegames in a text editor to ...
2
votes
Accepted
Persist global shader parameter
We can adapt the example shown in the Unity documentation here to get something that should work for your use case.
This still has the slight quirk that two instances of the ...
1
vote
Accepted
Getting info about the script a [PropertyAttribute] is attached to in Unity
You want the declaring type of the field that uses the attribute, not the declaring type of the attribute itself. (The attribute type is defined in its own class file, so it has no tie back to the ...
1
vote
Designing persistence in an ECS world subdivided into chunks
We had to solve a similar problem when developing Starlink: Battle for Atlas. The game takes place in a system of seven planets, and although only a small chunk of the current planet around the player ...
1
vote
Designing persistence in an ECS world subdivided into chunks
Solution A (Alternative) seems reasonable given the constraints you mention in your question and I suggest giving it a try. Regarding your hesitancy to stray from an ECS; notice that there is a ...
1
vote
Accepted
How can I serialize lists to JSON on mobile?
To be able to serialize some data using Unity's built in serializer, you will have to contain your data in a class. You can't simply serialize a list as is.
Something like this should work. You can ...
1
vote
How can I serialize lists to JSON on mobile?
The JSON.NET plugin for Unity officially supports "all Unity platforms including WebGL, except for WebPlayer, Windows 8.0 and Windows Phone 8.0."
1
vote
Extending a ScriptableObject to have a get property instead of a field, without losing serialized data
Here's a cool trick you can use:
...
1
vote
Accepted
How do you de/serialize a monobehaviour class?
Typically, you don't.
MonoBehaviour is not (de)serializable by JsonUtility.FromJson. Components only make sense when attached to ...
1
vote
Accepted
Deserialize only some fields from a JSON file
It looks like your problem is just a typo.
In the JSON, your array of robots is called "Robots" (uppercase R), but in your class you named it ...
1
vote
Accepted
How to properly format classes for JSON deserialization with JSON.net for Unity?
First, a few minor tweaks that might depend on your JSON library (it looks like you're using the Newtonsoft JSON library, rather than the built-in Unity JsonUtility)...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
serialization × 121unity × 69
c# × 40
json × 18
savegame × 12
c++ × 10
libgdx × 7
networking × 7
xml × 7
java × 6
xna × 6
editors × 6
multiplayer × 4
entity-component-system × 4
architecture × 3
box2d × 3
procedural-generation × 3
unreal × 3
data-structure × 3
component-based × 3
level-design × 3
file-format × 3
scriptable-object × 3
code-reflection × 3
animation × 2