A field initializer cannot reference the non-static field, method, or property

Why am I getting this error on my code “A field initializer cannot reference the non-static field, method, or property ‘BeastSheild.parent’”

 public GameObject sheild; 
    public GameObject parent;
    public int x = parent.transform.position.x;
    public int y = parent.transform.position.y;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            SpawnSheild();
        }
    }

    void SpawnSheild()
    {
        var spawnedSheild = Instantiate(sheild, new Vector3(x + .5f, y, 0), Quaternion.identity);
        spawnedSheild.transform.parent = parent.transform;
public int x = parent.transform.position.x;
public int y = parent.transform.position.y;

You cannot access other members of a class when initializing a variable.

If you want to initialize these x & y variables with the parent’s position, do so in the Awake or Start method:

GameObject parent;
public int x;
public int y;

void Awake() {
   x = parent.transform.position.x;
   y = parent.transform.position.y;
}

The parent.transform.position is not defined (created) before that object’s Awake is called, so essentially you’re trying to reference a null. This applies to the transform (and other components) on the same gameObject as well.