Setting up a class' mesh in c++

Hey guys.

I’m trying to set up a basic weapon class that has a mesh with detailed collision for when it’s lying around on the ground, a separate mesh for the skeleton (PHAT won’t let me use custom collision), and a capsule collision for raytracing so that you don’t need to look directly at the mesh - just nearby.

The code I have for this is as follows:

ACBaseGear::ACBaseGear()
{
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	RootComponent->SetRelativeLocation(FVector(0, 0, 0));
	ViewCollision = CreateDefaultSubobject<UCapsuleComponent>(TEXT("View Collision"));
	ViewCollision->AddRelativeRotation(FRotator(0.0f, 0.0f, 90.0f));
	GroundMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Ground Mesh"));
	GroundMesh->AttachTo(RootComponent);
	SkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh"));
	HeldMesh->SetVisibility(false, true);

However, dragging out a blueprint-derived class into the game world behaves adversely.

The transform of the BP will be wherever I set it to be - however, the components listed above initialize after I’ve released the mouse, and end up all being located at the absolute world origin. The picture above illustrates this.

I imagine my entire workflow/process for setting this up is flawed, but I can’t find any examples of how to do it right. Any advice?

Hello ,

I believe the only problem is that you’re setting the RootComponent’s relative location to be 0, 0, 0. Seeing as the Root Component is the “top” of the object/actor as far as Hierarchy goes, it’s doing 0, 0, 0 relative to UWorld, which is the whole level. This is causing it to move to 0, 0, 0 on construction, which happens everytime the blueprint is manipulated (i.e. moved with the transform widget) so it’ll seem like it is never moving.

If you remove that line, you should be good to go. Let me know if you still run into any issues.