After attaching the weapon to socket using C++ I was getting irregular charactermovement and camera becomes first person perspective from 3rd person view.I was able to spawn the weapon but after attaching it gives me bugged character movement and camera view.
Gun = GetWorld()->SpawnActor<AGun>(GunClassReference);
GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);
Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("weaponSocket"));
Gun->SetOwner(this);