Since I couldn’t call AttachToComponent() from EnemyWeapon directly I tried casting it to base, it compiled but didn’t work in game. Since same attachment code already works in my player character class I’m thinking the casting doesn’t work somehow.
Now I noticed attachment is working but weapon gets attached to my player character instead of the enemy character when I move player character next to the enemy. And the reason should be the OnOverlapBegin() function in base weapon class which equips the weapon to player character. Guess I need to disable it for the enemy character somehow.
Now I think about it, this doesn’t prove the attachment code on enemy character is working, if anything it isn’t working since weapon just spawns albeit invisible on the enemy and only gets attached to player character’s skeletal mesh socket if player character overlaps with it.
Fixed it by changing the root component from CollisionVolume(that overlap functions are attached to) to WeaponMesh in base weapon class and destroying the CollisionVolume in enemy class after spawning the weapon.