So i have a weapon inventory, and so some weapons, all of the same base class, i want to save all the variable they have, like current bullet, that they all access from the weapon base class but it changes for each weapon, when i exit the game i want to save all the “current bullet” for each weapon (Ex. rifle = 40 bullets, Shotgun 30 bullet, ecc…) and when i load back in they have the same value as i left, i have tried with a for each loop on my main weapon inventory array but it just doesnt work, or it sets me all the bullet of the first on eon the loop ot it set them to zero, i dont know how to resolve this, please help
So in the base class, you just write to the save game. This event can be used by all the other blueprints, because they inherit from the base class.
Why would you need a foreach loop? Are you looping over the weapons in the player, or something like that?
You might be able to get away with just an ‘end play’ event in the base class.
i was looping in the array to try get the BP instance of the main class because i have the array in the player character, can u specify what u mean by end play event, im kinda new to unreal and dont know everything there is, thank you
So in the parent, you can say
As long as the other weapons are children of this blueprint, they will automatically remember how much ammo they had.
The save game code is in a function library, so you can use it from anywhere
The map variable in the save game connects the class of the blueprint to the ammo amount
Job done, no loops
PS: If you have any trouble finding any of these nodes, always remember to drag from the previous node to open the search window. Don’t try just searching for the node without context, from ‘cold’.
omg thank u some much it works perfectly…now on i assume if i need to save something else for the weapon i need to still use this way…thank u for this and for let me discover the function libraries they a so usefull
You’re welcome
Yes, the common code goes in the parent, and only the enhancements go in the children.
Also, if you want to make a child that also removes functionality, you can ‘override’ the parent custom events, in the child, to do that.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.