x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Proper scene components declaration

When looking at this tutorial I don't understand why USceneComponent is declared at header but UCameraComponent is declared and initialized in constructor. Wouldn't it make more sense to declare all scene components at header and initialize them at constructor so header can give a good overview of class structure without digging .cpp? I've tried to declare UCameraComponent* at header, but this class is not defined here. Is this a bad practice to include appropriate header for camera component in my class header not in .cpp?

Product Version: UE 4.8
Tags:
more ▼

asked Jul 16 '15 at 09:58 PM in C++ Programming

avatar image

Unteroid
74 12 17 24

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Jul 17 '15 at 03:29 PM

avatar image

Gimmic
61 3 6 11

avatar image Unteroid Jul 17 '15 at 05:43 PM

Thank you for a very useful answer, sir!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question