Hi!
I have created a simple actor in c++ with a scene component as root, a box component and a static mesh component.
UPROPERTY(EditDefaultsOnly, Category = "Cell")
USceneComponent* RootCmp;
UPROPERTY(EditDefaultsOnly, Category = "Cell")
UBoxComponent* DetectorCmp;
UPROPERTY(EditDefaultsOnly, Category = "Cell")
UStaticMeshComponent* CellMesh;
The constructor code is:
RootCmp = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
SetRootComponent(RootCmp);
DetectorCmp = CreateDefaultSubobject<UBoxComponent>(TEXT("Detector"));
DetectorCmp->AttachToComponent(RootCmp, FAttachmentTransformRules::KeepRelativeTransform);
CellMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CellMesh"));
CellMesh->AttachToComponent(RootCmp, FAttachmentTransformRules::KeepRelativeTransform);
it’s pretty simple but I have an issue… When I spawn my object into the world, the box and static mesh components are located at world 0,0,0 so they have a local offset relative to my root component.
I have tried to set the relative location at 0,0,0 after AttachToComponent line and I have used SetupAttachment instead of AttachToComponent with no success. What’s wrong??
Thanks!