What is the difference between this: Code (CSharp): public class Example : MonoBehaviour { Image m_Image; public Sprite m_Sprite; void Start() { m_Image = GetComponent<Image>(); m_Image.sprite = m_Sprite; } and this: Code (CSharp): public class Example : MonoBehaviour { Image m_Image; public Sprite m_Sprite; void Start() { m_Image.sprite = m_Sprite; } Why do we need to use GetComponent? I always see this in the documentation but it seems to work fine without it.
The difference is, the second one will not work. It will raise a NilObjectException as soon as the script starts. m_Image is a private property, and (like all such) its value is nil until you assign some other value to it. GetComponent is one way to get such a value to assign.
You need it because the game engine doesn't automatically populate the field with a reference to the component, and there is no way to populate it automatically because there is no way for the game engine to know the intentions of the developer. You could in theory write an attribute that informs the game engine of your intentions, but you wouldn't gain anything from it because you'd just be shifting a one-line instruction from one position to another in the script. If you had additional code that needed to be executed that'd be different but you don't in your examples.
If you set m_Image as public you could populate it via drag/drop in the inspector to avoid using GetComponent. Otherwise what everyone else said.