So, I am trying to learn how to program with UE4, coming from Unity and online videos seem like a mess to me but the documentation online helps a lot. However… after attempting to follow along the tutorials I found myself with a problem…
In one of the tutorials (Creating and Attaching Components) it says to write in
USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT(“RootComponent”)); However the USphereComponent part at the beginning is giving me errors. Do I need to include a library or something?
Yes, you need to include a reference to the Sphere Component. The tutorial you are watching may be outdated, since, some versions ago the dependencies have been reduced, so to minimize compilation time. As a result, you will need to include the headers that you need.
In your specific case, you need to add the following include:
#include "Components/SphereComponent.h"
For further reference to where you can find the header to include, have a look to the documentation of the class you intend to use. In your case, visit the official documentation for USphereComponent and you can find the header at the bottom of the page. Alternatively, you can search the class within the engine code, and once found it, you can include the header.
You are welcome. It might be tedious at the beginning to include all the headers you need, and in general getting used to C++ in Unreal. However, once you have master it, you will appreciate the full power that it unlocks.