'Object reference not set to an instance of an object' error incorrect?

I’ve been working on an RTS concept for a few days now, and just ran into a problem that I can’t seem to solve.
Having made a placeholder for the first unit, I needed to give it a reference to an instance of the building that spawned it.
However, even though it has a reference to the instance, and the script it’s trying to get the ‘flagPos’ variable from, I still get the ‘NullReferenceException: Object reference not set to an instance of an object’ error.
What confuses me the most, though, is that the script functions just fine, but the error is still there to spam my console.
I could just ignore it, but being a perfectionist I’d rather not have an error stressing me out for the rest of the project.

The line in question is target = spawner.GetComponent<struc_Headquarters>().flagPos;

public class unit_Soldier : MonoBehaviour {
    //The Game Object that created this unit
    public GameObject spawner;

    Vector3 target;
    Vector3 previousTarget;
    Transform myTransform;

    float distance;
    float distanceToTarget;

    bool arrivedAtFlag;

    void FixedUpdate()
        target = spawner.GetComponent<struc_Headquarters>().flagPos;
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(new Vector3(target.x, transform.position.y, target.z) - transform.position), 5 * Time.deltaTime);


I agree the problem might be with prefabs