Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Error with AI going to Waypoints,Issues with AI tracking waypoints

$
0
0
Hello, I have been trying to develop my own AI based off of the Unity Pluggable AI lesson - however I've been running into a bit of an issue when trying to implement some sort of waypoint system to my AI. The error I keep getting is: NullReferenceException: Object reference not set to an instance of an object EnemyManager.SetupAI (System.Collections.Generic.List`1 wayPointList) (at Assets/EnemyManager.cs:25) GameManager2.SpawnAI (System.Collections.Generic.List`1 waypoints) (at Assets/GameManager2.cs:28) GameManager2.Start () (at Assets/GameManager2.cs:18) I've been trying to fix this, however no matter what I've done I haven't figured it out and I'm out of ideas. Below is the c# scripts for three of my classes with (the three associated with the making the AI and the error itself), any help would be appreciated, thanks! GameManager2 Class: using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameManager2 : MonoBehaviour { public GameObject[] m_EnemyPrefabs; public EnemyManager[] m_Enemy; public List wayPointsForAI; private WaitForSeconds m_StartWait; void Start () { m_StartWait = new WaitForSeconds (1); SpawnAI (wayPointsForAI); StartCoroutine (GameLoop ()); } private void SpawnAI(List waypoints){ for (int i = 0; i < m_Enemy.Length; i++) { m_Enemy [i].m_Instance = Instantiate (m_EnemyPrefabs [i], m_Enemy [i].m_SpawnPoint.position, m_Enemy [i].m_SpawnPoint.rotation) as GameObject; m_Enemy [i].m_PlayerNumber = i; m_Enemy [i].SetupAI(waypoints); } } } EnemyManager: using System.Collections; using System.Collections.Generic; using System; using UnityEngine; using UnityEngine.AI; [Serializable] public class EnemyManager { public Transform m_SpawnPoint; [HideInInspector] public int m_PlayerNumber; [HideInInspector] public GameObject m_Instance; [HideInInspector] public List m_WayPointList; private StateController m_StateController; private EnemyMovement m_Movement; private GameManager2 m_GameManager; public void SetupAI(List wayPointList){ m_StateController = m_Instance.GetComponent (); m_StateController.SetupAI(true, wayPointList); MeshRenderer[] renderers = m_Instance.GetComponentsInChildren (); } StateManager: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class StateController : MonoBehaviour { public State currentState; public State remainState; public Transform eyes; [HideInInspector] public NavMeshAgent navMeshAgent; [HideInInspector] public List wayPointList; [HideInInspector] public int nextWayPoint; [HideInInspector] public Transform chaseTarget; [HideInInspector] public float stateTimeElapsed; private bool aiActive; void Awake(){ navMeshAgent = GetComponent (); } public void SetupAI(bool aiActivation, List wayPoints) { wayPointList = wayPoints; aiActive = aiActivation; if (aiActive) { navMeshAgent.enabled = true; } else { navMeshAgent.enabled = false; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>