{"id":13728999,"url":"https://github.com/mackysoft/Unity-SerializeReferenceExtensions","last_synced_at":"2025-05-08T01:30:30.013Z","repository":{"id":37581070,"uuid":"354893679","full_name":"mackysoft/Unity-SerializeReferenceExtensions","owner":"mackysoft","description":"Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.","archived":false,"fork":false,"pushed_at":"2024-10-27T10:19:04.000Z","size":200,"stargazers_count":956,"open_issues_count":7,"forks_count":67,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-14T10:36:54.709Z","etag":null,"topics":["c-sharp","csharp","interface","polymorphism","serialization","serializereference","unity","unity-editor"],"latest_commit_sha":null,"homepage":"https://qiita.com/makihiro_dev/items/26daeb3e5f176934bf0a","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mackysoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mackysoft"}},"created_at":"2021-04-05T16:11:49.000Z","updated_at":"2025-04-13T12:16:10.000Z","dependencies_parsed_at":"2024-01-10T08:23:14.174Z","dependency_job_id":"413abd99-2ef6-49be-993f-9fc0dce3187e","html_url":"https://github.com/mackysoft/Unity-SerializeReferenceExtensions","commit_stats":{"total_commits":99,"total_committers":10,"mean_commits":9.9,"dds":"0.38383838383838387","last_synced_commit":"b7d76fb0c5133adc87e09c1d7aea87882a1d812a"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-SerializeReferenceExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-SerializeReferenceExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-SerializeReferenceExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-SerializeReferenceExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mackysoft","download_url":"https://codeload.github.com/mackysoft/Unity-SerializeReferenceExtensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252981378,"owners_count":21835416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","csharp","interface","polymorphism","serialization","serializereference","unity","unity-editor"],"created_at":"2024-08-03T02:00:53.428Z","updated_at":"2025-05-08T01:30:29.564Z","avatar_url":"https://github.com/mackysoft.png","language":"C#","readme":"﻿# Unity SerializeReferenceExtensions\n\n[![Build](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/actions/workflows/build.yaml/badge.svg)](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/actions/workflows/build.yaml) [![Release](https://img.shields.io/github/v/release/mackysoft/Unity-SerializeReferenceExtensions)](https://github.com/mackysoft/Unity-SerializeReferenceExtensions/releases) [![openupm](https://img.shields.io/npm/v/com.mackysoft.serializereference-extensions?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.mackysoft.serializereference-extensions/)\n\n**Inspired by [this post](https://qiita.com/tsukimi_neko/items/7922b2433ed4d8616cce).**\n\nThe `SerializeReference` attribute, added in Unity 2019.3, makes it possible to serialize references to interfaces and abstract classes.\n\nThe `SubclassSelector` attribute allows you to easily set subclasses of those abstract classes in the Editor that are serialized by `SerializeReference` attribute.\n\n![SubclassSelector](https://user-images.githubusercontent.com/13536348/118233552-03cd1780-b4cd-11eb-9e5b-4824e8f01f1d.gif)\n\n#### Features\n\n- Easily set subclass by popup.\n- **[New]** Type finding by fuzzy finder.\n- **[New]** Override the type name and path by the `AddTypeMenu` attribute.\n- **[New]** Available `CustomPropertyDrawer` for subclasses.\n- **[New]** Restore values of previous object from JSON when subclass is changed. (required Unity 2021.3 or later)\n- **[New]** Copy \u0026 Paste the subclass properties. (required Unity 2021.3 or later)\n- **[New]** Clear \u0026 reset the subclass properties. (required Unity 2021.3 or later)\n- **[New]** Covariance / Contravariance support. (required Unity 2023.2 or later)\n\n\u003e See below for the reason for the limitation of versions less than Unity 2021.3.\n\u003e \n\u003e https://blog.unity.com/engine-platform/serializereference-improvements-in-unity-2021-lts\n\n## 📥 Installation\n\n#### Install via `.unitypackage`\n\nDownload any version from releases.\n\nReleases: https://github.com/mackysoft/Unity-SerializeReferenceExtensions/releases\n\n#### Install via git URL\n\nOr, you can add this package by opening PackageManager and entering\n\n```\nhttps://github.com/mackysoft/Unity-SerializeReferenceExtensions.git?path=Assets/MackySoft/MackySoft.SerializeReferenceExtensions\n```\n\nfrom the `Add package from git URL` option.\n\nIf you are specifying a version, enter `#{VERSION}` at the end, as shown below.\n\n```\nhttps://github.com/mackysoft/Unity-SerializeReferenceExtensions.git?path=Assets/MackySoft/MackySoft.SerializeReferenceExtensions#1.1.9\n```\n\n#### Install via Open UPM\n\nOr, you can install this package from the [Open UPM](https://openupm.com/packages/com.mackysoft.serializereference-extensions/) registry.\n\nMore details [here](https://openupm.com/).\n\n```\nopenupm add com.mackysoft.serializereference-extensions\n```\n\n## 🔰 Usage\n\n```cs\nusing System;\nusing UnityEngine;\n\npublic class Example : MonoBehaviour {\n\n\t// The type that implements ICommand will be displayed in the popup.\n\t[SerializeReference, SubclassSelector]\n\tICommand m_Command;\n\n\t// Collection support\n\t[SerializeReference, SubclassSelector]\n\tICommand[] m_Commands = Array.Empty\u003cICommand\u003e();\n\n\tvoid Start () {\n\t\tm_Command?.Execute();\n\n\t\tforeach (ICommand command in m_Commands) {\n\t\t\tcommand?.Execute();\n\t\t}\n\t}\n\n\t// Nested type support\n\t[Serializable]\n\tpublic class NestedCommand : ICommand {\n\t\tpublic void Execute () {\n\t\t\tDebug.Log(\"Execute NestedCommand\");\n\t\t}\n\t}\n\n}\n\npublic interface ICommand {\n\tvoid Execute ();\n}\n\n[Serializable]\npublic class DebugCommand : ICommand {\n\n\t[SerializeField]\n\tstring m_Message;\n\n\tpublic void Execute () {\n\t\tDebug.Log(m_Message);\n\t}\n}\n\n[Serializable]\npublic class InstantiateCommand : ICommand {\n\n\t[SerializeField]\n\tGameObject m_Prefab;\n\n\tpublic void Execute () {\n\t\tUnityEngine.Object.Instantiate(m_Prefab,Vector3.zero,Quaternion.identity);\n\t}\n}\n\n// Menu override support\n[AddTypeMenu(\"Example/Add Type Menu Command\")]\n[Serializable]\npublic class AddTypeMenuCommand : ICommand {\n\tpublic void Execute () {\n\t\tDebug.Log(\"Execute AddTypeMenuCommand\");\n\t}\n}\n\n[Serializable]\npublic struct StructCommand : ICommand {\n\tpublic void Execute () {\n\t\tDebug.Log(\"Execute StructCommand\");\n\t}\n}\n```\n\n#### Supported Types\n\nThe `SubclassSelector` attribute supports types that meet the following conditions.\n\n- Public or nested private\n- Not abstract\n- Not generic\n- Not unity object\n- Serializable attribute is applied.\n\n\n## ❓ FAQ\n\n### If the type is renamed, the reference is lost.\n\nIt is a limitation of `SerializeReference` of Unity.\n\nWhen serializing a `SerializeReference` reference, the type name, namespace, and assembly name are used, so if any of these are changed, the reference cannot be resolved during deserialization.\n\nTo solve this problem, `UnityEngine.Scripting.APIUpdating.MovedFromAttribute` can be used.\n\nAlso, [this thread](https://forum.unity.com/threads/serializereference-data-loss-when-class-name-is-changed.736874/) will be helpful.\n\n#### References\n- https://forum.unity.com/threads/serializereference-data-loss-when-class-name-is-changed.736874/\n- https://issuetracker.unity3d.com/issues/serializereference-serialized-reference-data-lost-when-the-class-name-is-refactored\n\n# \u003ca id=\"help-and-contribute\" href=\"#help-and-contribute\"\u003e ✉ Help \u0026 Contribute \u003c/a\u003e\n\nI welcome feature requests and bug reports in [issues](https://github.com/mackysoft/XPool/issues) and [pull requests](https://github.com/mackysoft/XPool/pulls).\n\nIf you feel that my works are worthwhile, I would greatly appreciate it if you could sponsor me.\n\nGitHub Sponsors: https://github.com/sponsors/mackysoft\n","funding_links":["https://github.com/sponsors/mackysoft"],"categories":["C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackysoft%2FUnity-SerializeReferenceExtensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmackysoft%2FUnity-SerializeReferenceExtensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackysoft%2FUnity-SerializeReferenceExtensions/lists"}