Access the class members, actor rotate.


en: It is necessary to turn the incoming Actor, but I can’t access the class members. Please help.

ru: Необходимо повернуть входящий Актор, но не могу получить доступ к членам класса. Прошу помощи.

Hi, I’m a total newbie programmer. But I’ll tell you what I think helpful ( take it with a grain of salt ).

  • If you want to just declare a pointer or a reference of a certain class, then you only need to “forward declare” the class.
    ( that seems to be not your problem since you have AActor pointer already in the function signature and no error therein ).

  • If you want to access a member inside the class AActor however, then you need to add #include “GameFramework/Actor.h” in the file you’re working in.

If this function that you posted is in the header file, then just add #include “GameFramework/Actor.h” up in your file.
If this function is in the cpp file then add #include “GameFramework/Actor.h” in the header file as well.

Please note that any #include you add must be above YourClass.generated.h line.

I hope that would help.

If that worked, I’ll just add whenever you access a pointer member, then you have to add the If(pointer) ahead of the sentence to check whether the pointer value at that moment is null or valid, because accessing a null pointer is a fatal error in C++. So you write like this: If(Actor) Actor->SetActorRotation ( myNewOrientation);

This expression If(Actor) is equivalent to writing If ( Actor != nullptr ) or If( Actor!=0 ). The first version is the shortest, so we use it a lot.

You have to do that each time you access the pointer, or alternatively you can start the function by If (Actor = 0 ) return; for once and then forget about that in the rest of the function statements. ( if the logic in the function agrees with that of course, which mostly will do )

These are important safety measures.

Anyway, take all what I mentioned ( particularly the first half ) with a grain of salt.

Alzaher, Thank you very much. Happened. I’m smarter thanks to you.