SpawnActor wrong location and attach fail in C++

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, of in Tick(), the issues will occur.

So what I want to know is why this happen?

Can I fix it? (If I want it 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() );
  }
}

I found that the reason that the actor spawned in wrong location because I didn’t override the Tick() in weapon class. It makes sense since the actor has to keep refine its location in each frame;

However, I still cannot attach the weapon to my character. I hope that someone can explain the cause.