How to spawn a Weapon dynamically in a Lyra Game

Hello, somebody can help me?

I’m making a game with Lyra Game Starter Pack, and I made a Blueprint subclass of the Lyra Weapon Spawner adding some features, like asking to press F to pick up the weapon and destroy it from the scene on pick up.

But I’m trying to add the ability to drop weapon and spawn dynamically. Thank you in advance, and sorry my English.

------------------ Portuguese ----------------------------
Olá, alguém pode me ajudar?

Estou fazendo um jogo usando o Lyra Game Starter Pack, e eu fiz uma Blueprint herdada do Lyra Weapon Spawner adicionando alguns recursos, como pedir ao player apertar F para pegar a arma e em seguida destruir o objeto.

Mas eu estou tentando adicionar a habilidade de largar a arma e spawndar dinamicamente. Desde já agradeço, e desculpem pelo inglês.

Hi,
I’m not sure that I understood correctly what you want but I think you want a way to handle the drop/pickup.
The way I’d do it is when the player drops the weapon you destroy it and spawn a new Blueprint in front of the player (mid-air with physics enabled or do a line trace towards the ground to find a proper location to spawn it) that acts like the original Weapon Spawner:
if you press F you pick up the weapon and destroy this new BP

1 Like

Hi, thank’s man, it’s almost this.

But the problem is how I can to get the Weapon Definition from Player Inventory to give for the Weapon Spawner? Or if I could at least get the Weapon Mesh from player, I would be very happy.

I tryed to do the inverse of the LyraWeapon Spawner, but no success…
image

I’m now trying to do this on the C++, because I think that if I change the LyraWeaponSpawner and create a function on player for instanciate and spawn the blueprint.


Very thank you, more a time.

I’d RPC the server to spawn a Lyra Weapon Spawner w/ the item type you dropped.

1 Like

In you weapon spawner make variable for the weapon definition public and expose it on spawn. That way, when you call the Spawn Actor From Class in your Player BP you can plug it in directly from your Player data.

1 Like

Thank you very much, everyone. It worked.

I also saw this video that helped me: (10) UE5 Lyra Tutorial | Dropping items after death (RUS) - YouTube

I changed the LyraWeaponSpawner.h for expose weaponDefinition on spawn, and I changed the DropWeapon game abillity for spawn the weapon.

LyraWeaponSpawner.h

GA_DropWeapon



This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.