Local Networking, getting a null error when spawning

I have gameObjects (the enemies) spawned one by one by a spawner script.
The spawner script have an arrey of Serialized scriptableObjects (waveConfig), each containing different variables regarding the gameObjects.

The spawner looks like this:

private IEnumerator SpawnAllEnemies(WaveConfig waveConfig)
    {

        for (int enemyCount = 0; enemyCount < waveConfig.GetNumberOfEnemy(); enemyCount++)
        {
                 newEnemy = Instantiate(
                waveConfig.GetEnemyPrefab(),
                waveConfig.GetWayPoints()[0].transform.position,
                Quaternion.identity) as GameObject;
            newEnemy.GetComponent<EnemyPathing>().SetWaveConfig(waveConfig);
           SpawnEnemy();
            yield return new WaitForSeconds(waveConfig.GetTimeBetweenSpawns());
        }
    }
        private void SpawnEnemy()
    {
        NetworkServer.Spawn(newEnemy);
     }

When I run on both a local build and the editor,
with the build as server,
the build runs just fine, and on the editor I can see the gameObjects spawned in the same location (but not the editors’ player) and the screen is stuck with this error:

NullReferenceException: Object reference not set to an instance of an object
EnemyPathing.Start () (at Assets/Scripts/EnemyPathing.cs:14)

If the build as the client and the editor the server, it seems to run OK, but the bulid is giving the error.

any Ideas ?

The error says it occurs in EnemyPathing.Start() on line 14. Please show that method and state which line is 14.

public class EnemyPathing : MonoBehaviour
{
    WaveConfig waveconfig;
    float moveSpeed;
    List<Transform> waypoints;
    int waypointIndex = 0;
    // Start is called before the first frame update
    void Start()
    {
    moveSpeed = waveconfig.GetMoveSpeed();   [I]<== line14[/I]
    waypoints = waveconfig.GetWayPoints();
    transform.position = waypoints[waypointIndex].transform.position;
    }

The waveconfig is not set to any value before you use it.

Ok, so the spawner is calling:

            newEnemy.GetComponent<EnemyPathing>().SetWaveConfig(waveConfig);

This line (from the first post) is a part of a corutine called by another corutine called in the start method.

It is calling a methods on the EnemyPathing script:

    public void SetWaveConfig(WaveConfig waveconfig)
    {
        this.waveconfig = waveconfig;
    }

It seems that everything working fine until a client is connecting. I have also tried make the spawner script run only on the server with:

  void Start()
    {
                if (isServer == true)
                {
               StartCoroutine(beginSpawningCoroutine());  
                 }

It did not help. dos it have to do with who is calling the script or how many times it is caled ?

Thank you for engaging !
I have found a solution, but still have a question…

The thing was that EnemyPathing script (which is part of every enemy spawned),
has a Start and Update methods that access the varuable (waveconfig).

I have added:

       if (hasAuthority == false)
        {
            return;
        }

Now, from what I understand, this would only let the server access to this script, right ?
Is there another way to do so without having to chack for hasAuthority for every gameObject every frame ?

If the server has authority over the networked gameobject then yes hasAuthority would only be true on the server. It is possible to assign authority to one of the clients though, and in that case hasAuthority would be true on that client. You can also try checking isServer.