Question about unreal engine #include headers and Visual Assist X

HI @ChaosDuck, I can help clear up some of your questions, but probably not all of them. And all code below is hastily written for demonstration purposes, just use it as a guideline.

Intellisense: the UE4 codebase is pretty big, and depending on your pc environment you might get mixed results on the speed of symbol retrieval. This link ( Setting Up Visual Studio for Unreal Engine | Unreal Engine Documentation ) goes over setting up your IDE for best performance. Note the MaxCachedTranslationUnits option, this seems to help if you can spare the memory.

Forward Declaration : If you declare a variable which is a pointer of a class, you cannot assign it a value without including the header file of the class type. This is because it is treated as an incomplete class. You have to forward declare it (Epic tends to use the C style declaration) like this and then assign it a value in the body of the constructor in your .cpp file.

/** 
 * YourClass.h file
 */

// Standard forward declaration
class UPhysicsHandleComponent;

UCLASS()
class YourClass : public AActor
{
     // Shorthand forward declaration
     class UPhysicsHandleComponent* PhysicsHandle;
};

Then you’ll want to assign null in the implementation file

/**
 * YourClass.cpp
 */

YourClass::YourClass(const FObjectInitializer& OI)
     : Super(OI)
{
     PhysicsHandle = nullptr;
}

Rama does a good job of explaning this here (A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums). Just note that you can only forward declare pointers.

Your third question is similar to your second question, but it’s hard to know EXACTLY what is going on without seeing the output from VS. My first inclination is that UInputComponent.h is already included somewhere in the class hierarchy of whatever class your are deriving from. For instance, if you are working in your own player controller class, which inherits off of APlayerController, then APlayerController.h already includes the InputComponent header. In this case, if the compiler is still giving you a hard time, again, forward declaration will probably solve the issue.

Hope this helps =]

Sorry I can’t look at the code snippits you provided earlier until later tonight.

I don’t know of any way to improve intellisense beyond the IDE setup I mentioned earlier.

So I looked at the FindComponentByClass which will return a UActorComponent reference. You’ll probably want to keep the PrimitiveComponent include in your file because I expect you will have to cast it before you can call the function you want. Like this

    UPrimitiveComponent* MyPrimComp = Cast<UPrimitiveComponent>
             (GetComponentByClass(UPrimitiveComponent::StaticClass()));
    if(MyPrimComp)
    {
          float m = MyPrimComp->GetMass();
    }

It may compile after all, but when you call it you could get a runtime error without the PrimitiveComponent definitions.

There shouldn’t be any performance impact from including headers in an implementation file. As your project gets larger, there may be an impact on compile times, but unless you’re making something incredibly large, I would treat it as negligible until it becomes a problem.

I haven’t seen any issues packaging for Windows or Mac.

is it normal for VAX to not show the autocomplete/suggestion listbox if I don’t have the header included? I don’t know how my thing got messed up but with the tutorial series im following, the person gets all the autocomplete/ suggestions in the listbox without including those headers.

1.an example of a problem im having is if I don’t have #include “Classes/Components/PrimitiveComponent.h” and and I try to get the mass of an object by doing something like Actor->FindComponentByClass()->GetMass();
It still lets me compile but sometimes Intellisense won’t show me the drop list with all the methods, it will stop get MyActorName->FindComponentByClass()-> and say “No member Available”.

can someone please explain to me the deal with these header files. I don’t really know how to explain it properly so Here is a bit of code https://codepaste.net/s6o494 here you can see that I include no header but it still compiles but the thing is that like i said when i try to do like GetOwner()-> nothing shows up afterward, but if I do have all the headers then it will show up properly, Im really confused with this.

2.The next one is when im declaring a variable (something like UPhysicsHandleComponent* PhysicsHandle = nullptr in my .h file, why is that I NEED to have the #include “PhysicsEngine/PhysicsHandleComponent.h” in the header line? otherwise I get a compile error.

3.The third confusing thing is why is that if a declare a variable in my .h file just like before but this times its UInputComponent* InputComponent = nullptr;
I NEED to include the #include “Classes/Components/InputComponent.h” in my CPP file and not the .h file? I get some random errors when i move it to my .h file.

I’m really confused with all this and i feel like im just being dumb or something. Please someone explain this to me, is it that unless you are declaring a new type of variable, the header files are used just to help with intellisense with the auto complete/suggestion list box? or are they required for when you are shipping your game?

The 2 links here are for the .cpp and .h file, can you tell me what headers I can remove and if i need to include any additional header files? although its working completely fine, I want to understand why the headers are there for. https://codepaste.net/25q3zy
and https://codepaste.net/j85oob

Thank you

Please tell me if I’m not allowed to post these links, I can post it to where ever you want.

also I downloaded Visual assist x, but it seems to missing some methods for ue4 in the suggestion drop list. like InputComponent->BindAction, BindAction shows up with intellisense but not with visual assist X, am i doing something wrong or did not install it properly?

Thank you for answering the question, so I understand that I MUST have the header if im declaring a pointer i.e AActor* myactor;
but what about the rest?
Like #include “Classes/Components/PrimitiveComponent.h”
I can compile with or without this, but should i include or remove it?

im suing the primativecomponent class to get the weight of a static item in my scene FindComponentByClass()->GetMass(); If i remove this, my intellisense messes up, is there a way to fix intellisense or is it better to include the header?

sorry if you didn’t understand what i said, i don’t know how to explain it. But i have no compilation errors and the game works as intended and no runtime erros when i calculate the mass.
if i don’t have the primitivecompoenent header file, it still works fine, its only the intellisense that doesn’t work until i include the header file.

so what i want to know is should i include the header files? is there any performance impact if i include the header files? and is it worth it to include the header files just so i can get the autocomplete/suggestion list box in intellisense?

ok, thank you very much. I think I will keep including the header files, I want to use intellisense. also does not including the header files makes any different when you package your game?