Why use a getter at all?

In the C++, what is the purpose of the getter?

When I did the challenge, I created the public variable and made it BlueprintReadOnly. This allowed me to call the variable directly into the Blueprint through the Aiming Component Ref without going through the getter.

Is there any particular reason it was done the way @Ben did it?

Good practice. That’s all it is.
Public variable are frowned upon in the programming community because they can easily make things messy in large projects.
So they’re just trying to teach you good code. :slight_smile:

Makes sense. I realise now that as I have the variable in blueprint, it can be changed there which is a no-no.

Thanks for your reply.

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

Privacy & Terms