I need to have the name of the object and a certain amount of information about it in the form of a number, I need to do this with the help of a dictionary, i.e. take by key its name and by value this number, or better by two lists where the scheme is the same, but you will need to implement a simple search.

What to choose, a dictionary (I don’t know if it is serialized using JsonUtility) or lists?

    1 answer 1

    No, it does not serialize.

    Unity has an ISerializationCallbackReceiver interface. There are two methods that are called before and after serialization. You can continue to use the dictionary, but turn it into two lists before serialization, and then turn them into a dictionary after these lists.

    If there are not many objects, you can just have one sheet and, through the Find (Predicate predicate) method, look for the element you need

    • In fairness, the first link is an example of serialization / deserialization of the dictionary. Good answer. - RiotBr3aker 2:57 pm
    • So at the output, it’s necessary to refer to this object, I can’t change it directly in the scriptable object - k0vpack
    • @ k0vpack, in which plan you can not? There the first link directly code how to serialize the dictionary - M. Green
    • @ M.Green well, it’s not quite that, I don’t have fields to write, I’ll have a SerializationCallbackScript script - k0vpack
    • @ k0vpack, is the class code big? If you attach it to the question, maybe I can help) but I don’t understand the problem much - M. Green