I've tried to spawn an weapon and attach it to my character
But it
a). is spawned in wrong location
b). doesn't attached to character
However, I've found that this issue depends on where I place the code.
If I place the code in PostInitializeComponents(), it will spawned and attached as I expected.
However, if I place it in a function, for example, in Tick(), the issue will occur.
So what I want to know is why this happen?
Can I fix it? (If I want it to be a function, not in PostInitializeComponents() )
here's the code I use:
if( bpWeapon )
{
AWeapon *weapon = ( AWeapon * ) GetWorld()->SpawnActor<AWeapon>( bpWeapon, GetActorLocation(), GetActorRotation() );
if( weapon )
{
const USkeletalMeshSocket *socket = GetMesh()->GetSocketByName( "hand_rSocket" );
socket->AttachActor( weapon, GetMesh() );
}
}
But it
a). is spawned in wrong location
b). doesn't attached to character
However, I've found that this issue depends on where I place the code.
If I place the code in PostInitializeComponents(), it will spawned and attached as I expected.
However, if I place it in a function, for example, in Tick(), the issue will occur.
So what I want to know is why this happen?
Can I fix it? (If I want it to be a function, not in PostInitializeComponents() )
here's the code I use:
if( bpWeapon )
{
AWeapon *weapon = ( AWeapon * ) GetWorld()->SpawnActor<AWeapon>( bpWeapon, GetActorLocation(), GetActorRotation() );
if( weapon )
{
const USkeletalMeshSocket *socket = GetMesh()->GetSocketByName( "hand_rSocket" );
socket->AttachActor( weapon, GetMesh() );
}
}
Comment