Why we can't use public string StoryText { get; private set; }

I was quite surprised when I saw Rick writing an actual getter in C#. From my little experience in C# this is quite unusual as most developers use public string StoryText { get; set; } .This is called Property and it is a C# feature for more than a decade .

I was even more surprised to see that properties do not work in C# ( I was expecting to see _storyText on the Inspector) which explains why Rick wrote a getter. But why is not working? Could someone explain please?

Hi Angelos,

Welcome to our community! :slight_smile:

Which version of Unity do you use?

In past versions of Unity, it was not possible to expose properties in the Inspector. I think this was changed in one of the last few Unity versions. Give it a try. Since this course caters to beginners, Rick does not want to introduce too many new concepts. However, if you are experienced in programming, feel free to apply your knowledge.

Properties do work. The question is: Do they appear in the Unity editor? Unity is not C#, so you’ll have to test certain things to figure out if they work.

Hopefully, this helped.


See also:

I will give it another shot in one of the other projects of the course. I used the previous LTS version. Perhaps in one of the 2021 versions of Unity it could work. I will update the post once I have a working example.

How are you getting on with this, @Angelos?

Hello again. Thanks for coming back to me. No I did not have the chance to test it yet. Hopefully I will have more spare time in the next few days so I can make more progress and test the C# property.

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

Privacy & Terms