Hi everyone,
I’m trying to attach a sword to my character’s hand.
In order to do this,i’m using this function:
void ABaseCharacter::SpawnWeaponInCharacterHand(FName HandSocketName)
{
FActorSpawnParameters spawnParams;
spawnParams.Owner = this;
SwordActor = GetWorld()->SpawnActor<ABaseSword>(ABaseSword::StaticClass(),spawnParams);
SwordActor->AttachRootComponentToActor(this, HandSocketName, EAttachLocation::SnapToTarget, true);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, HandSocketName.ToString());
}
The problem is that the sword,is attached to the character’s root bone instead of the HandSocket like it should.
If i instead use the “Attach Actor To Component” function from the character blueprint,the result is correct:
Blueprint:
Result:
Note that i checked the function parameter with the debug message,and the bone name is actually right.
So the question is…why it works on blueprint side,but not on C++?
Am i doing something wrong?
Thanks in advance.