Default is protected for Unreal classes?

Hi, I just wanted to verify that this is correct.

When implementing the ExecuteTask the instructor mentions that the default section (public, protected, private) is protected so in the implementation on the ClearBlackboardValue.h he’s creating a protected section to place it.

What is confusing here is that coming from a C++ background like I am, classes always default to private instead and while I did research this briefly via Google (and might have found an answer that seems to suggest the “GENERATED” sets this, it mentioned that it set it all to public effectively making it a struct and not a class so that didn’t exactly match what the instructor here mentioned).

So I’m just curious as to whether Unreal adds a specific type of code that changes the default for these from private to protected or was this incorrectly stated in the training?

GENERATED_BODY() used to end in public: but I don’t think it does that anymore. I assume @sampattuzzi just accidentally said protected instead of private?

Maybe, however he did create a protected section and put his implementation there (and again, it’s used in a protected section for another BTTask CPP we create in either the next or second to next section) so it would appear to be a mistake if that’s the case in the lecture.

Well it certainly can’t be private or we couldn’t override it. I did misspeak about the default being protected.

Well, based on what I see here, it’s definitely not in a protected section so we are for whatever reason able to override it as a private function. I can confirm that I’m having absolutely no issues with it like that as I didn’t implement it in the manner you did, I kept it outside of it’s own section so it would use whatever the default was for the class (which would typically be private).

This screenshot was taken from the training video which is where I had spotted this during the lecture and prompted the question.

GENERATED_UCLASS_BODY is the old macro which does public: at the end of it. If you look at the docs you will see that it’s a public function.

1 Like

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

Privacy & Terms