I am making an SO with the definition for an Enemy, like this:
public class Enemy_SO : ScriptableObject
{
public string enemyName;
[Header("AI Agent Settings")]
public int speed;
public int angularSpeed;
}
And I am attaching it to the Enemy GameObject like this:
public class EnemyController : MonoBehaviour
{
public Enemy_SO enemy_1;
public NavMeshAgent enemyAgent;
private void Start()
{
enemyAgent = GetComponent<NavMeshAgent>();
Debug.Log("name: " + enemy_1.name);
enemyAgent.speed = enemy_1.speed;
}
}
On play the console outputs:
NullReferenceException: Object reference not set to an instance of an object
EnemyController.Start () (at Assets/Scripts/Enemies/EnemyController.cs:29)
name: Enemy 1
UnityEngine.Debug:Log(Object)
EnemyController:Start() (at Assets/Scripts/Enemies/EnemyController.cs:29)
So it throws a null reference on line 29, but then it correctly outputs line 29, and all the agent variables are correctly set in the inspector during play. Is there any way to get rid of the error? Do I just ignore it?