Skip to main content
19 votes
Accepted

How to make a field visible (attachable) in the inspector but inaccessible through code (private-like)?

You're looking for the SerializeField Attribute From the docs: Force Unity to serialize a private field. You will almost never need this. When Unity serializes your scripts, it will only serialize ...
Cameron Edwards's user avatar
15 votes
Accepted

How can I create a custom PropertyDrawer for my Point struct?

The reason that you can't change any of the values is because the Point struct isn't a Vector2 data type. A ...
user3797758's user avatar
  • 3,641
5 votes
Accepted

Unity - How to serialize / show private fields and custom types in Inspector?

The [SerializeField] attribute instructs Unity to serialize the field regardless of the accesibility. All three fields below gets serialized and shows up on ...
starikcetin's user avatar
  • 5,295
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

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 ...
Tudvari's user avatar
  • 761
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 ...
Ed Marty's user avatar
  • 5,229
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 ...
DMGregory's user avatar
  • 135k
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 ...
Luke Briggs's user avatar
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 ...
Tallek's user avatar
  • 121
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: ...
DMGregory's user avatar
  • 135k
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

How to make a field visible (attachable) in the inspector but inaccessible through code (private-like)?

You can show your private variable By adding SerializeField attribute before the variable. Something like this [SerializeField] private Button button; The above ...
Muhammad Faizan Khan's user avatar
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 ...
Matster2's user avatar
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

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
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 ...
Bartimaeus's user avatar
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: ...
Kevin's user avatar
  • 6,234
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: ...
Stephen's user avatar
  • 1,030
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 ...
Filip Milovanović's user avatar
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++ ...
Philipp's user avatar
  • 120k
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 ...
Charly's user avatar
  • 742
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. (...
DMGregory's user avatar
  • 135k
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. ...
Theraot's user avatar
  • 27.2k
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 ...
Philipp's user avatar
  • 120k
1 vote

Fast Serialization for Multiplayer Gaming

is serializing an entire object an acceptable way to send game info over the internet. Yes and No, if the objects data is reasonably small and serialization is fast there's no problem. You generally ...
VaTTeRGeR's user avatar
  • 776
1 vote
Accepted

How to add to a MonoBehavior array from an Editor script in Unity

The property's array size needs to be edited every time (or appropriately before) an operation is made. WRONG. Not sure what I changed to make it work, but I laid out my code in the original ...
Gmanicus's user avatar
1 vote

Loading a list of items from JSON, all entries are null

Here is you object declaration: public class QuestionCollection { public QuestionChoicesAnswerHintExplanation[] questions; } And here is what you do: ...
real4x's user avatar
  • 171
1 vote

Unity3D MonoBehaviour in .dll loses serialized data when dll is updated

Solved. The issue was that I had renamed the class and in doing so, it provides a missing script error and dumps the data. Since my editor automatically adds the required script I did not notice this ...
GorillaOne's user avatar
1 vote

Unity: Component not being serialized

You'll notice the docs for SetDirty point out that this method has been replaced: Prior to Unity 5.3, this was the primary method of marking objects as dirty. From 5.3 onwards, with the ...
DMGregory's user avatar
  • 135k
1 vote

Still having problems using Json data in Unity

...
Big T Larrity's user avatar

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