ArgumentOutOfRangeException: Argument is out of range

I did everything in the Video but I still got this error. Please Help!!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyPathing : MonoBehaviour
{

    [SerializeField] List<Transform> waypoints;
    [SerializeField] float moveSpeed = 2f;
    int waypointIndex = 0;

    // Use this for initialization
    void Start()
    {
        transform.position = waypoints[waypointIndex].transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        Move();
    }

    private void Move()
    {
        if (waypointIndex <= waypoints.Count - 1)
        {
            var targetPosition = waypoints[waypointIndex].transform.position;
            var movementThisFrame = moveSpeed * Time.deltaTime;
            transform.position = Vector2.MoveTowards
                (transform.position, targetPosition, movementThisFrame);

            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
        if (waypointIndex == 3)
        {
            Destroy(gameObject);
        }
    }
}

I am getting the exact same issue, and it seems that the issue is the fact that the waypoint list thinks that it has 0 elements. The code ran fine if I added elements to the list through the code but not otherwise. Has anyone found a solution to this problem?

Hi,

If either of you would like your share your project files with me I will be happy to take a quick look.

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.

I have the same issue. Please help !!

Privacy & Terms