Skip to content

Commit 51c2040

Browse files
committed
Add docs about new C++ serialization callbacks
1 parent 6ed053a commit 51c2040

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

manual/scripting/advanced/refactoring-renaming.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ void MyType::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier
7979
}
8080
```
8181
***
82+
83+
## Serialization callbacks
84+
85+
Flax supports serialization callback methods that can be used to manipulate an object before and/or after its serialization and deserialization by the serializer. That can be used to perform more advanced data upgrading after version changes. See [C++](../cpp/serialization.md) and [C#](../serialization/index.md) documentation sections to learn more.

manual/scripting/cpp/serialization.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,50 @@ private:
1818
API_FIELD(Attributes="Serialize") float PrivateVarSaved;
1919
```
2020
21+
## Serialization callbacks
22+
23+
Flax supports serialization callback methods. A callback can be used to manipulate an object before and/or after its serialization and deserialization by the serializer.
24+
25+
* `OnSerializing`
26+
* `OnSerialized`
27+
* `OnDeserializing`
28+
* `OnDeserialized`
29+
30+
Example:
31+
32+
```cpp
33+
#include "Engine/Serialization/ISerializeModifier.h"
34+
35+
API_CLASS() class FLAXENGINE_API MyScript : public Script
36+
{
37+
API_AUTO_SERIALIZATION();
38+
DECLARE_SCENE_OBJECT(MyScript);
39+
40+
public:
41+
API_FUNCTION(Attributes="OnSerializing", Hidden)
42+
void OnSerializing(const CallbackContext& context)
43+
{
44+
}
45+
46+
API_FUNCTION(Attributes="OnSerialized", Hidden)
47+
void OnSerialized(const CallbackContext& context)
48+
{
49+
}
50+
51+
API_FUNCTION(Attributes="OnDeserializing", Hidden)
52+
void OnDeserializing(const CallbackContext& context)
53+
{
54+
// 'context.Modifier->EngineBuild' holds engine version of saved data
55+
}
56+
57+
API_FUNCTION(Attributes="OnDeserialized", Hidden)
58+
void OnDeserialized(const CallbackContext& context)
59+
{
60+
// 'context.Modifier->EngineBuild' holds engine version of saved data
61+
}
62+
};
63+
```
64+
2165
## Json
2266

2367
Flax uses [RapidJSON](https://rapidjson.org) library to serialize data into *json* format.

manual/scripting/serialization/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ Here are listed various hints about Flax serialization:
2929
* Avoid recursive references for custom objects types. It's better to use loop-references for scene objects.
3030
* When performing code refactoring see [this tutorial](../advanced/refactoring-renaming.md) about supporting old data format loading
3131

32-
## Serialization Callbacks
32+
## Serialization callbacks
3333

3434
Flax supports serialization callback methods. A callback can be used to manipulate an object before and/or after its serialization and deserialization by the serializer.
3535

36-
* OnSerializing
37-
* OnSerialized
38-
* OnDeserializing
39-
* OnDeserialized
36+
* `OnSerializing`
37+
* `OnSerialized`
38+
* `OnDeserializing`
39+
* `OnDeserialized`
4040

4141
Example:
4242

0 commit comments

Comments
 (0)