Assinging values in inspector instead of using GetComponent

Is there any reason we’re not using GetComponent to get InputReader and CharacterController?
Is this because we would have to use another variable as a property to get their references from other scripts?
Thank you

1 Like

Nathan is demonstrating a relatively new way of managing properties. In older versions of Unity, this [field: SerializeField] public Component Component {get; private set;} was simply not available to use. If you wanted to set a field to be assignable in the inspector, it had to be fully private, public, or protected.

You actually could use GetComponent for these values rather than making them [field: SerializeField] references. It’s still best to qualify them with {get; private set;} as you still want to make them publicly readable without being publicly modifable.

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms