- Home /
Utilizing Unity's default serializer
Is it possible to somehow manually call Unity's default serializer?
I would need something similar to this:
var toSerialize = new Something { X = 3 };
var serializationTarget = File.Open("<path>"); // or something similar
UnitySerializer.Serialize(toSerialize, serializationTarget);
So basically I want to explicitly trigger serialization and also define where the serialized output goes.
Is this possible?
Answer by Louis Watson · Sep 28, 2014 at 11:39 PM
Your link directs you to the local copy of the documentation on the hard drive. Document may be in different places based on operating system of general computer set up.
Well not exactly. I want to trigger serialization myself, not react to the serialization that happens.
ins$$anonymous$$d of triggering serialization you react to it via those methods. consider this code:
public class $$anonymous$$yClass
{
public int X;
public $$anonymous$$yClass(int x) { X = x; }
}
public class $$anonymous$$yScript : $$anonymous$$onoBehaviour, ISerializationCallbackReceiver
{
[SerializeField] // Defining this attribute or declaring a public serializable field is what "Triggers" Unity's serialization
int myX;
public $$anonymous$$yClass $$anonymous$$yVariable;
public void OnAfterDeserialize()
{
$$anonymous$$yVariable = new $$anonymous$$yClass(myX);
// React once Unity has finished deserialization so use the loaded data
}
public void OnBeforeSerialize()
{
myX = $$anonymous$$yVariable.X;
// React before Unity saves so store the data you need
}
}
Once again: That is not what I need. I want to decide when the serialization takes place and where the serialized output is placed and that CANNOT be achieved by your suggestion.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Serializing strings to XML C# 1 Answer
A type of object being compared to another in serialization 1 Answer