0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SerializeReference + SubclassSelectorのついているフィールドをInspectorで設定してもPlayすると外れてしまう

Last updated at Posted at 2023-08-30

バグの再現方法

version: 2021.3.21f1

上のパッケージをインストールして,適当なInterfaceをFieldにもつクラスを生やして,Inspectorで設定する
(自分の場合はScriptableObjectだったがMonoBehaviourでも再現すると思う)

namespace Hoge
{
    public class Fuga : ScriptableObject
    {
        [SerializeReference, SubclassSelector]
        public Interface i;
    }

    public interface Interface { }
    public class ImplA : Interface { }
    public class ImplB : Interface { }
}

namespaceを変更する

namespace HogeHoge
{
    public class Fuga : ScriptableObject
    {
        [SerializeReference, SubclassSelector]
        public Interface i;
    }

    public interface Interface { }
    public class ImplA : Interface { }
    public class ImplB : Interface { }
}

参照が変わるため,アタッチが外れnullになるので,再度Inspectorで設定

Playするとなぜかiがnullになる(何度繰り返しても)

解決策

一回,Attribute([SerializeReference, SubclassSelector])を消して読み込み直す
その後,Attributeを付け直す

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?