trying attach a USceneComponent to my UCameraComponent by codes below:
//create components
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
SceneComp = CreateDefaultSubobject<UGrabber>(TEXT("SceneComp"));
//attach Camera to current root
Camera->SetupAttachment(GetRootComponent());
//attah my SceneComp to Camera making it a hierarchy.
SceneComp->AttachToComponent(Camera,FAttachmentTransformRules::SnapToTargetIncludingScale);
the result visually looks great in editor:
Root
----Camera
--------SceneComp
but when i try for getting world location of my SceneComp using GetComponentLocation(),
whole editor was crashed:
void AFirstPersonCharacter::BeginPlay()
{
Super::BeginPlay();
FString start = Grabber->GetComponentLocation().ToString(); <---crashed on this line.
UE_LOG(LogTemp,Warning,TEXT("SceneComp is at: %s"),*start);
}
it seems like the way of attaching USceneComponent to another component was mistaken.
anyone could help?