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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using UnityEngine;
using UnityEngine.Scripting.APIUpdating; // Written to use MovedFromAttribute
using LogicToolkit;

namespace NewNamespace
{
    [MovedFrom(false, "OldNamespace", "OldAssembly", "OldType")]
    public class NewType : ActionComponent
    {
        // Contents
    }
}

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.

  1. Be sure to back up your data.
  2. Right-click the file or folder you want to migrate from the Project window.
  3. 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.

  1. Select Edit > Project Settings from the menu.
  2. Select “Editor” category
  3. 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

  1. Open the file you want to change in a text editor.
  2. Find references such as:
1
2
3
4
5
6
7
references:
    version: 2
    RefIds:
    - rid: 2053174280601206785
      type: {class: OldType, ns: OldNamespace, asm: OldAssembly}
      data:
        ...
  1. Change to correct information
5
type: {class: NewType, ns: NewNamespace, asm: NewAssembly}

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.