Rename Type
This section describes renaming the NodeComponent type.
NodeComponent etc. are designed to be serialized using Unity's SerializeReference.
SerializeReference is a function that internally stores assembly names, namespaces, and type names, and deserializes based on that information. Because it is referenced by various names, there is a problem that when the name is changed, it cannot be deserialized and the reference becomes disconnected.
To avoid data references being broken, you can apply MovedFromAttribute or edit the YAML file directly.
MovedFromAttribute
If you change the assembly (asmdef), namespace, or type name, you can notify Unity's serialization function of the type name change by applying MovedFromAttribute to the type.
Code example
|
|
Migration process
When applying MovedFromAttribute, Unity will automatically perform the migration process if the type is not found when loading data.
However, please note that the changes will not be reflected in the file, so you will need to save it again to save the migrated data.
If you want to migrate multiple files at once, please re-serialize the files.
- Be sure to back up your data.
- Right-click the file or folder you want to migrate from the Project window.
- Select Logic Toolkit > Force Reserialize from the menu.
This will re-serialize the selected file or all files in the selected folder.
As of Unity 6000.0, it is not supported when the generic type or the type used for the generic parameter is changed. See Direct file editing below.
Edit file
If MovedFromAttribute does not work, or if you want to change the assembly or namespace all at once, you can migrate by directly changing the YAML file.
**Please be sure to back up your data before proceeding as editing errors may result in data corruption. **
Setting Asset Serialization Mode
To save scene files etc. in YAML format, you need to configure Project Settings.
- Select Edit > Project Settings from the menu.
- Select “Editor” category
- Set “Mode” of “Asset Serialization” to “Force Text”.
- There is no particular problem if it was originally “Force Text”.
- If it is other than “Force Text”, you will need to save the target file again.
Edit YAML file
- Open the file you want to change in a text editor.
- Find references such as:
|
|
- Change to correct information
|
|
If you are not sure how to write the correct information, please create a separate scene that uses the target NodeComponent and check the saved contents.