First of all, don’t ever look at nativised generated code to learn.
Secondly, i highly recommend a C++ course to learn the basics. Then a UE4 C++ course to understand some core concepts of the engine and its C++.
Third, to your actual question:
Remove that include you added, now in that same header file, add
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
class UStaticMeshComponent* StaticMeshComponent;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
class USphereComponent* SphereCollision;
now in your .cpp file, you will see the “constructor”,
AInteractable_CPP::AInteractable_CPP()
{
PrimaryActorTick.bCanEverTick = true;
}
add the following lines;
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("StaticMeshComponent");
RootComponent = StaticMeshComponent;
SphereCollision = CreateDefaultSubobject<USphereComponent>("SphereCollision");
SphereCollision->SetupAttachment(RootComponent);
so finally it looks like:
AInteractable_CPP::AInteractable_CPP()
{
PrimaryActorTick.bCanEverTick = true;
StaticMeshComponent= CreateDefaultSubobject<UStaticMeshComponent>("StaticMeshComponent");
RootComponent = StaticMeshComponent;
SphereCollision = CreateDefaultSubobject<USphereComponent>("SphereCollision");
SphereCollision->SetupAttachment(RootComponent);
}
Now add to your cpp file, the following includes
#include "Components/SphereComponent.h"
#include "Components/StaticMeshComponent.h"
Now close editor, compile and reopen editor, and you will see your actor will have the static mesh component.q