Serialize class with serializable fields,

Hello, I got a very specific question, and I haven’t been able to find answer. I want to serialize my class, which contains serializable fields. Here’s some code:

[Serializable]
public class House
{
	[SerializeField]
	public string Name;

	[SerializeField]
	public House Neighbor;
}

Update: (I wanted to narrow the question, but apparently did too much. Here’s more details)
I have script, which I call in editor, it assigns values to these fields, which I want to use at runtime.
Name field persists when running the game, and I can use it, no problems. While Neighbor == null at runtime.

“Normal” serializable classes are treated like structs by the serialization system. You can’t have circular references in such a class since every reference to a “House” would be immediately instantiated by the inspector. This would result in an infinite chain of class instances.

The only references which Unity can actual serialize as references are references to other assets. More specifically classes derived from UnityEngine.Object. The classes you can use as base type are MonoBehaviour for custom components which are bound to a gameobject, or ScriptableObject which are standalone assets. Note that ScriptableObjects need to be stored as actual asset in the project.

See Script serialization for more information. Specifically the section “When might the serializer behave unexpectedly”