Accessors

JEFF SHAW
1 min readDec 13, 2020

--

Took a closer look at Get and Set Accessors. The C# survival guide has some good material in the Properties section: Properties — https://gamedevhq.teachable.com/courses/885507/lectures/16227344

This one on YouTube was also informative: https://www.youtube.com/watch?v=ZjoVSAcf63w

We’ve been writing our own regular methods for doing Get and Set, and this is a streamlined built in technique to access and change variables across scripts. Using these methods helps to maintain OOP Encapsulation and keep a scripts variables private and access controlled in a standard means. The accessor structure defining the Get/Set are a little different from our regular Methods. It automatically enforces variable access type for Set without specifying. You maintain 2 diff variable definitions, one upper case (Public accessor) and one lower case(private). One of the interesting aspects is how in the cases of variables setup to use Get& Set accessors, the variable naming convention changes, and these variables are capitalized. This had confused me in the past for some time. While autoproperties appear cleaner, we can’t serialize these variables in inspector, you must assign them in Start. I’m starting to get a better understanding of how this all fits together and plan to review it with interns with some examples next week.

Still working on more debugging. The lives system is working pretty well, but still has some errors. Been continuing to clean up the code overall. I had 3 versions of camera shake, only one was used. Other stuff muddling the player script. A had too many Debug.Log comments I never cleaned up, and preened those from other scripts to more easily trace the current problem.

--

--

JEFF SHAW

Unity VR Developer (VRX Virtual Reality Experiences VRX)