I studied some C++ and with the Following Lines i could retrieve the current Equiped Weapon in c++:
i used it in LyraGameplayAbility_RangedWeapon.cpp
within the following function:
FTransform ULyraGameplayAbility_RangedWeapon::GetTargetingTransform(APawn* SourcePawn, ELyraAbilityTargetingSource Source) const
if (Source == ELyraAbilityTargetingSource::Custom) {
…
ULyraEquipmentInstance* LEI_SR = GetAssociatedEquipment();
TArray<AActor*> SpawnedActorsSR = LEI_SR->GetSpawnedActors();
AActor* SpawnedActor_SR = SpawnedActorsSR[0]; //B_ColtPistol_SR_C_0
USkeletalMeshComponent* WeaponMeshSR = SpawnedActor_SR->GetComponentByClass();
// We already have Weapon Socket Location and Rotation (Quat) separately → No need for >SocketTransform
//FTransform WeaponMeshTransformSR = WeaponMeshSR->GetSocketTransform(SocketNameSR);
FVector WeaponSocketLocationSR = WeaponMeshSR->GetSocketLocation(SocketNameSR);
FRotator WeaponSocketRotationSR = WeaponMeshSR->GetSocketRotation(SocketNameSR);
FQuat WeaponSocketRotationQuatSR = WeaponMeshSR->GetSocketRotation(SocketNameSR).Quaternion();
//SR SourceLocation, AimQuat
//Original – SourceLoc = GetWeaponTargetingSourceLocation();
SourceLoc = WeaponSocketLocationSR;
AimQuat = WeaponSocketRotationQuatSR;
The Current Weapon is always the first index in Array (0).
Not sure if i should include UPROPERTY() so the Pointer doesnt get Garbage Collected or is it here not necessary?
Because i have observed, that after every Weapon Equip / unequip the SpawnActor gets incremented, B_ColtPistol_SR_C_0 → B_ColtPistol_SR_C_1 ->B_ColtPistol_SR_C_2 and so on. Not sure if this is normal behaviour. What i know is that Lyra destroys the actor after unequip and spawns it completely new after equip, but keeps all the “old” references. Is there a need to destroy them or Garbage Collect them manually or something like that or is this normal behaviour and UE manages it under the hud? I think at somepoint the increment will reach its limit. This behaviour is also here when player gets killed and respawned. B_Hero_Mannequin_SR_C_0 → B_Hero_Mannequin_SR_C_1 → B_Hero_Mannequin_SR_C_2.
Kind regards,
Ivan