I am getting the ol’ null reference exception right after trying to hookup the WaveConfig Scriptable Object. Showing code first, then inspector screenshots.
WaveConfig.cs GetWayPoints() method
public List<Transform> GetWaypoints()
{
var waveWaypoints = new List<Transform>();
foreach (Transform child in pathPrefab.transform)
{
waveWaypoints.Add(child);
}
return waveWaypoints;
}
EnemyPathing.cs Variable Declarations, Start(), Update(), and Move() methods
[SerializeField] WaveConfig waveConfig;
List<Transform> waypoints;
[SerializeField] float moveSpeed = 2f;
int waypointIndex = 0;
private void Start()
{
transform.position = waypoints[waypointIndex].position;
waypoints = waveConfig.GetWaypoints();
}
private void Update()
{
Move();
}
private void Move()
{
if (waypointIndex <= waypoints.Count - 1) // Error points to this line
{
var targetPos = waypoints[waypointIndex].position;
var movementThisFrame = moveSpeed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position,
targetPos,
movementThisFrame);
CheckArrival();
}
else
{
Destroy(gameObject);
}
}
I hope it’s something silly I’m missing!