Scenario: I made a new map, and made a c++ blueprint class that derives from a pawn. I gave it components, but whenever I drag and drop it into the world, one of its components (in our case, the box collider) always fixes its own position to the center of the map. I heavily doubt it has anything to do with my code, because I never coded it to set its position, it doesnt even have much, but even without the attempted FAttachmentTransformRules::KeepRelativeTransform, it would still do it. Here is a picture.
Here is my .h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Components/StaticMeshComponent.h"
#include "Components/BoxComponent.h"
#include "TestPawn.generated.h"
UCLASS()
class UE_PLAYGROUND_API ATestPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ATestPawn();
UPROPERTY(EditAnywhere)
UStaticMeshComponent* StaticMesh;
UPROPERTY(EditAnywhere)
UBoxComponent* BoxCollider;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
and my .cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Components/BoxComponent.h"
#include "TestPawn.h"
// Sets default values
ATestPawn::ATestPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh"));
StaticMesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
BoxCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Box Collider"));
BoxCollider->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
BoxCollider->InitBoxExtent(FVector(100.0f, 100.0f, 100.0f));
}
// Called when the game starts or when spawned
void ATestPawn::BeginPlay()
{
Super::BeginPlay();
BoxCollider->SetHiddenInGame(false);
}
// Called every frame
void ATestPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ATestPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}