The following code works in Blueprint
I’ve attached my skeletal mesh components like this
Now, I’d like to migrate to C++. First, I replace the declaration of the meshes to happen inside my C++ class for the actor:
// Sets default values
ABaseWeapon::ABaseWeapon()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComp"));
SetRootComponent(SceneComponent);
RootComponent = SceneComponent;
MeshFPP = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshFPP"));
MeshFPP->SetOnlyOwnerSee(true);
MeshFPP->SetupAttachment(SceneComponent);
MeshTPP = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshTPP"));
MeshTPP->SetOwnerNoSee(true);
MeshTPP->SetupAttachment(SceneComponent);
}
Unfortunately, now I get this:
Since I’ve essentially done the same thing the Blueprint was doing, I’m not sure what’s wrong. I understand it says the types are misaligned, but I believe my variables are of all the same types as they were in the blueprint. I assume self
refers to the root scene component, so I do not understand why it now says This blueprint (self) is not a PrimitiveComponent, therefore ' Target ' must have a connection.
when self should still be referring to my root scene component.