I’m trying to move the following Blueprint function to C++
but the behaviour I’m getting isn’t what I was expecting. The wheels (the Static Meshes I’m trying to attach) end up having their transform relative to the socket instead of the origin, resulting in them being somewhere they shouldn’t be.
How it is with the Blueprint function:
How it is with my C++ implementation:
I don’t get why they behave differently.
My implementation:
wheel_front_l = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Wheel Front L"));
wheel_front_r = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Wheel Front R"));
wheel_rear_l = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Wheel Rear L"));
wheel_rear_r = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Wheel Rear R"));
brake_pad_l = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Brake Pad L"));
brake_pad_r = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Brake Pad R"));
USkeletalMeshComponent* skm = GetMesh();
FAttachmentTransformRules attach_rules = FAttachmentTransformRules(EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, true);
wheel_front_l->AttachToComponent(skm, attach_rules, TEXT("wheel_front_turn_l"));
wheel_front_r->AttachToComponent(skm, attach_rules, TEXT("wheel_front_turn_r"));
wheel_rear_l->AttachToComponent(skm, attach_rules, TEXT("wheel_rear_l"));
wheel_rear_r->AttachToComponent(skm, attach_rules, TEXT("wheel_rear_r"));
brake_pad_l->AttachToComponent(skm, attach_rules, TEXT("wheel_front_l"));
brake_pad_r->AttachToComponent(skm, attach_rules, TEXT("wheel_front_r"));