I would say that it’s best practice to declare all components in the header that you want to be able to modify after construction, such as if you want to be able to change camera field of view at a later stage, then it’s better to declare it in the header. Otherwise it would be difficult retrieving a reference to the object that you want to modify without having a variable as a reference.
Regarding including the appropriate header file for the camera component. Since the UCameraComponent* variable is a pointer, you should simply forward declare using the class keyword before the variable declaration like so:
class UCameraComponent* MyCamera;
alternatively place it before the class declaration like so:
class UCameraComponent;
UCLASS()
class SOME_API ACustomActor : AActor
{
GENERATED_BODY()
public:
UCameraComponent* MyCamera;
}
That way you tell the compiler that you want to reserve space in memory for the pointer for use at a later stage. And then when you want to utilize the UCameraComponent you include the header file in the .cpp file like normal.
~Per “Gimmic” Johansson