Potential issue when serializing prefabs and nested SerializedReference properties

Issue #902 new
William Besnard created an issue

Hi, I posted a forum message thinking it might be a Unity bug, but I’m not so sure anymore. It doesn't involve Odin’s Serialization, but I think Odin may be messing with something here. Here’s a copy of my post:

Hi, 

Sorry to revive an old thread, but there is again a bug with SerializeReference and prefabs in 2022.2.1f

Consider the following scripts: 

[code=CSharp]using UnityEngine;

namespace BFT

{

public class RefTestComponent : MonoBehaviour

{

[SerializeReference]

public IRefTest RefTest;

}

}[/code]

[code=CSharp]namespace BFT

{

public interface IRefTest

{

}

}[/code]

[code=CSharp]namespace BFT

{

public interface INestedRefTest

{

}

}[/code]

[code=CSharp]using UnityEngine;

namespace BFT

{

public class NestedRefTestImplementation :INestedRefTest

{

public GameObject go;

[SerializeReference]

public INestedRefTest NestedRef;

}

}[/code]

[code=CSharp]using UnityEngine;

namespace BFT

{

public class RefTestImplementation :IRefTest

{

public GameObject go;

[SerializeReference]

public INestedRefTest NestedRef;

}

}[/code]

When putting the following script in a prefab, linking to its own gameobject, then when creating an instance of the prefab, only the first reference (the one in RefTestImplementation) points to itself in the instance, the rest of the fields are pointing to the prefab game object:

On the image, the blue one is correct, the red ones are wrong.

Is that the intended way, or is that a bug?

Comments (0)

  1. Log in to comment