Can i get a Variable from a socket attached blueprint?

Hello,

My Problem: I make a VR game and want a gun, where you can attach a magazine with a bullet variable. So I can reuse magazine with lesser bullets.

I use on the weapon a socket, to bring the magazine with a collision to it place. Even removing works fine. I have no idea to save the current number of bullets to the magazine and get it when it’s attached to the weapon. Weapon and magazines are to separate blueprints.

Did someone have any ideas how to solve this problem or the right direction to it? Tutorials for VR a rare and for the socket solution I can’t only find 2. Both of them show only how you can attach 2 things to each other, nothing more.

Thanks for any help

It depends on how your magazine is spawned. Are the magazines spawned from your gun blueprint?

No, from the magazine bag blueprint. The Bag is on the hip, so you can go to the collision sphere with your hand, push the controller trigger button and spawn the magazine in your hand.

There’s a lot of ways to do this, we would need to see how you switch weapons to get a really specific answer. But here is my best guess:

On your bag blueprint, create an array variable of Magazine object references

Every time you spawn a magazine, add it to the array variable

Every time you switch a magazine, somehow get the index of the magazine you are switching to, then use that index to get the reference from your array variable. Then you will have access to whatever variables are on your magazine, like current bullets.

If you don’t know how to get the index, I will need to see a screenshot of how you switch weapons

For now, I have only one Weapon. To switch a weapon you must drop it and take anther one. I have only grab and drop function for the hands. To carry more weapons you have socket slots, on your wrist, where you can drop the weapon, and it’s attaching to the slot. To decide which magazine get spawned I will write a check for what weapon is grabbed. But I do this after I get one weapon fully working.

I don’t know how to get the index.

You will have to tell the Bag blueprint which magazine you are picking up, because it doesn’t know which one you are holding.

What happens on your grab function? How does it know which magazine you are grabbing? Is there a line trace or overlap event or something like this? If so, you could get a reference from there