UnassignedReferenceException

UnassignedReferenceException: The variable pathPrefab of WaveConfig has not been assigned.
You probably need to assign the pathPrefab variable of the WaveConfig script in the inspector.
WaveConfig.GetWaypoints () (at Assets/Scripts/WaveConfig.cs:20)
EnemySpawner+d__3.MoveNext () (at Assets/Scripts/EnemySpawner.cs:20)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
EnemySpawner:Start() (at Assets/Scripts/EnemySpawner.cs:13)

the enemy prefab is stacking and dont know what’s going on
PS Im new thanks!

here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
[SerializeField] List waveConfigs;
int startingWave = 0;
// Use this for initialization
void Start()
{
var currentWave = waveConfigs[startingWave];
StartCoroutine(SpawnAllEnemiesInWave(currentWave));
}

private IEnumerator SpawnAllEnemiesInWave(WaveConfig waveConfig)
{
    for (int enemyCount = 0; enemyCount < waveConfig.GetNumberOfEnemies(); enemyCount++)
    {
        var newEnemy = Instantiate(
            waveConfig.GetEnemyPrefab(),
            waveConfig.GetWaypoints()[0].transform.position,
            Quaternion.identity);
        newEnemy.GetComponent<EnemyPathing>().SetWaveConfig(waveConfig);
        yield return new WaitForSeconds(waveConfig.GetTimeBetweenSpawns());
    }
}

}

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.

Remember you can also look at the lecture code changes via the link in the Resources of each lecture.


See also:

my code is the same one from the Resources and still not working whit the same error

Double click on the error message. To which line in your code does it refer?

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms