Variable value set in custom editor resetting when entering play mode

I have 2 scripts with classes with this structure

public class foo: MonoBehaviour {
	public A a;
}

public class A {
	// stuff
}

public class B: A {
	float x, y, z;
}

I have a few class inheriting from A with their own variables.
I’m trying to show and modify the x, y, z variables in the Foo class inspector. I manually added 3 floats in its Editor class and assign the value to the B class similar to this

EditorGUILayout.PropertyField(x);
EditorGUILayout.PropertyField(y);
EditorGUILayout.PropertyField(z);

Foo f = (Foo)target;
B b = (B)f.a
if (b != null) {
	b.x = x;
	b.y = y;
	b.z = z;
}

I don’t think this is recommended and even if it’s ok, since x, y, z are not serialized the variables are reset when hitting play.

The other thing I tried is make A and B serializable and use FindPropertyRelative() to get x, y and z.

a = serializedObject.FindProperty("a");	// I can't cast to B like i did before
x = a.FindPropertyRelative("x");	// So this is null even if f.a is an instance of B

So I ran out of ideas although, my second solution feels more idomatic with serialized fields in Unity. But I’m still not comfortable with custom editors so I’m stuck here

A and B must be [Serializable], also x,y and z must be serialize field

public class foo: MonoBehaviour {
	public A a;
}
[Serializable]
public class A {
	// stuff
}
[Serializable]
public class B: A {
	[SerializeField]
	private float x;
	[SerializeField]
	private float y;
	[SerializeField]
	private float z;
}

Other option is inherit from scriptable object.