Why those newly added properties were set to "private"?

Hi all,

I was wondering why those newly added “Open Angle” and “Pressure Plate” properties were set to “private” in this lecture, I tried to set them in “public” also works.

Since Ben didn’t mention the reason why they should be in “private” in the video, may I know the purpose behind this?

I’m also confused why properties were still exposed in the GUI of UE Editor when they were set to “private”?

Cheers,
Parker

1 Like

To keep them encapsulated. They can be exposed to the GUI even though it’s private is just because of how UE4 works, it still makes logical sense (imo) since none of the code (C++ and blueprint) can access it apart from the class itself.

Thanks for your answer DanM.

I did several tests and found that properties can be exposed to the GUI is because of the UPROPERTY marcos “VisibleAnywhere” and “EditAnywhere”, without these marcos, they cannot be shown in the GUI even they were set to “public”.

I understood that properties would not be touched outside the class when they’re set to “private”, but still don’t understand why we should encapsulate them here? I could not figure out why these “Open Angle” and “Pressure Plate” properties must set to “private”? Is it just for educational purpose here in order to extend our knowledge?

Oh I thought thought you meant why should the macro work if it’s private, yes that’s what those macro’s do.

Because that’s the whole point of encapsulation, “hiding” the data members and exposing only the interfaces.

1 Like

Privacy & Terms