I’ve got the following code:
using UnityEngine; using System.Collections; public class SpriteManager : MonoBehaviour { Mesh mesh; void Start () { if(GetComponent< MeshFilter >()) { print("Attached"); } mesh = GetComponent< MeshFilter >().mesh; } }
I do get the ‘Attached’ message in the console but it also throws the following error:
NullReferenceException: Object reference not set to an instance of an object
SpriteManager.Start
Any ideas why this error pops up?