Repository navigation
en architecture reflection serialization
中文 | English | Docs | Repository
Reflection drives three things at once: editor interfaces, scene and Prefab serialization, and the scripting API manifest. All three share one metadata source, which is why "fields that can be serialized" and "fields that can be edited" match by default.
C++ declarations (CLASS / STRUCT / ENUM / PROPERTY / FUNCTION)
|
v
Tools/MetaParser parses
|
v
Runtime/<Module>/Gen/ and Project/<Target>/Gen/
|
v
runtime registration into the reflection database
|
+--> Inspector controls
+--> object graph serialization
+--> scripting API manifest
Never edit anything under a Gen/ directory by hand.
CLASS(MyType) : public NLS::meta::Object
{
public:
GENERATED_BODY()
PROPERTY()
float speed = 1.0f;
};ENUM(MyMode) : uint8_t
{
A,
B
};GetXxx / SetXxx pairs marked with FUNCTION() form a property automatically. A getter alone gives a read-only property; a setter alone gives a write-only one.
When the original declaration body cannot be changed:
MetaExternal(MyType)
REFLECT_EXTERNAL(MyType, "MyType")Private members use the REFLECT_PRIVATE_* family for out-of-class binding.
- A type body containing
GENERATED_BODY()goes through text parsing. - Top-level
ENUM()declarations also go through text extraction. -
MetaExternal/REFLECT_EXTERNALgo through out-of-class declaration parsing. -
CppAststill exists in the toolchain but is not the parsing path for most reflected type bodies today.
Stay consumer driven: reflect a type only when a real consumer exists.
| Question | Conclusion |
|---|---|
| Does the editor need to view or edit it? | Reflect |
| Does serialization need to walk its fields? | Reflect |
Does runtime code create, query, or compare it through meta::Type? |
Reflect |
| Is it a value type or enum another reflected property depends on? | Reflect |
| Is it just a cache, helper implementation, transient state, or a handle no consumer can handle? | Do not reflect |
Being public is not a reason to reflect a type.
Each runtime module generates its own link function, for example LinkReflectionTypes_NLS_Base, LinkReflectionTypes_NLS_Core, and LinkReflectionTypes_NLS_Engine. Database initialization calls them to complete registration.
Scenes and Prefabs share one object graph format:
| Element | Representation |
|---|---|
| Object | GUID-backed ObjectRecord
|
| Ordinary state | Reflected fields |
| Lifecycle ownership |
$owned relationship |
| In-scene reference | Non-zero fileID, empty guid, type = NonAssetType
|
| Asset reference | Non-zero fileID, valid asset guid, asset type; filePath is only a hint |
| Prefab difference | Patch operations instead of per-object-type payloads |
The legacy $ref and $asset forms are no longer accepted by the reader. Use $owned for ownership and the fileID/guid/type shape for references.
ObjectGraphSerializer writes reflected fields and records graph relationships separately. ObjectGraphInstantiator instantiates in stages:
- Create known objects.
- Apply reflected fields.
- Resolve relationships.
- Rebuild scene caches.
- Editor policy: preserve unknown records and unresolved asset references with diagnostics so a document round-trips without losing recoverable data.
- Runtime policy: fail on unknown or invalid data instead of silently dropping it.
The difference is deliberate: the editor needs tolerance, the runtime needs determinism.
The GameobjectSerialize adapter and the SerializedSceneData / SerializedActorData / SerializedComponentData payload model are not part of the maintained runtime scene load path.
Components whose state cannot be expressed with reflected fields can override:
virtual bool SerializeObjectGraphProperties(
std::vector<NLS::Engine::Serialize::PropertyRecord>& properties) const;
virtual bool DeserializeObjectGraphProperties(
const std::vector<NLS::Engine::Serialize::PropertyRecord>& properties);The engine owns the graph format and the component owns its payload, keeping the dependency one-way. Script components use exactly this path to store script asset metadata and field overrides.
- Prefab Workflow shows how patch operations express overrides.
- Scripting API Reference shows how the manifest becomes bindings in two languages.
Nullus Engine
中文
- 认识 Nullus
- 安装与快速入门
- 使用编辑器
- 场景与对象
- Prefab 工作流
- 资产与内容管线
- 渲染、材质与光照
- 大场景与资源管理
- 游戏逻辑与脚本
- 用户界面
- 动画与角色
- 物理与交互
- 音频、特效与媒体
- AI 与联网
- 平台、构建与发布
- 扩展与引擎架构
- 调试、性能与质量
- 参考手册
- 示例与发展路线
English
- Getting to Know Nullus
- Install and Quick Start
- Using the Editor
- Scenes and Objects
- Prefab Workflow
- Assets and Content Pipeline
- Rendering, Materials, and Lighting
- Large Scenes and Resource Management
- Gameplay and Scripting
- User Interface
- Animation and Characters
- Physics and Interaction
- Audio, Visual Effects, and Media
- AI and Networking
- Platforms, Builds, and Releases
- Extending the Engine
- Debugging, Performance, and Quality
- Reference
- Examples and Roadmap