this is not accessing the member that is the issue:
in C++ protected allows for Child and friend (these get cumbersome) classes access as though they were public, while classes that are not derived from or, “fried of” is treated as private.
this is not an Unreal thing this is a C++ thing
the error you are getting is to do with includes specifically, and tangentially about inheritance
my guess is that you have
PlayerCharacter.h
class APlayerCharacter : ACharacter
then in your AAICharacter.h
#include "PlayerCharacter.h"
class AAICharacter : public APlayerCharacter
when you inherit like this the Header, and the Header only gets copy and pasted wherever the #include ***
so if that file being included doesn’t include all the stuff that will be needed to deal with the class then those things need to be included as well.
where you are forward declaring the UPaperSpriteComponent
when you do “class UPaperSpriteComponent
” in the PlayerCharacter.h, and then only doing the actual include in the PlayerCharacter.cpp.
you need to also include the header for the PaperSpriteComponent
in your AICharacter.cpp or if the type is integral to your design move the include to the PlayerCharacter.h
where everything dealing with the APlayerCharacter
will probably need to understand what a UPaperSpriteComponent
is and does.
the advantages of forward declarations is to prevent recursion, or potentially infinite recursion in the Header compilation pass of the compiler (A needs B, B needs C, and C needs A this include structure could easily lead to to infinite recursion), so we use forward declaration to prevent potentially this recursion nightmare.
when the forward declarations fall down is when everything in a chain needs to know about, and how to communicate with a class, forward declaring it will lead to more includes then just putting the include in the highest of the hierarchy