Hey all, so my character stats in my game instance BP are all carrying over to the next level just fine… The problem I’m having is how do I get the weapon in my hands and my secondary weapon to carry over as well? I have them saved as a reference on my character, then saved to the game instance when i travel, then on Begin Play on my character set the reference on my character to my game instance reference same as with the other variables but the weapons don’t carry over… Ive looked at different tutorials but Ive only ever seen others carrying over variables like Health, or Coins, which I have working, just not the weapons I have. Do I have to save the weapons as a class reference and not an object? Or do I have to make the weapons a save game object or something different than how the other variables are saved?
Dilute down the weapon information into a struct that will hold the main descriptors (spawn class, ammo count, primary / secondary weapon, attachment bone slot)
Pass the struct into the game instance and when you load the level recreate the weapons from the struct (spawn actor from class => set ammo amount => set position => attach) and initialize their references inside of the character.
■■■■ that was fast! Thank you I will give it a go and update ya
Okay so its been awhile, haven’t got to work on my project much but I was able to get everything to carry over except for the static mesh and Im not really sure why. It’s saved as a variable but when I try to get it on spawn I get a " no reference found" error for my static mesh… the weapon is spawning and is attached correctly, has the correct stats ect… Just no static mesh, any thoughts? I tried even just setting the visibility to true and setting the static mesh to a new one on spawn but I cant get it to appear at all even though everything else has carried over.
Once you pass in the static mesh to the game instance “play back” the information that you just set through a get and a print string of the name of the newly set variable.
Are you saving it to a struct inside of GI or as a raw variable there?
The statìc mesh is saved in the struct with all of the other variables. I have a static mesh component variable in the struct that I get once I spawn my new weapon and set the new weapons static mesh to the one I have saved in the struct. And yeah the struct variables are set inside the GI.
I tied a print string to get the display name of the static mesh I should be receiving but I’m not getting anything from it. It seems like the variable isn’t saving but I’m not sure lol
Are you setting the static mesh in the struct via a reference?
Place a get of the struct variable near the save function. Drag on it’s out pin (right side) and set by reference. Try setting the static mesh there, otherwise you might just be making a copy of the struct.
Holy hell I just got it to work! So I was trying to carry over a static mesh component variable but I had to use a static mesh object reference and then set my new static mesh component to whatever the saved object reference is. Thanks for the help with using the struct and for the suggestions! Felt like I was going in circles lol it makes alot more sense now though
Glad to see you got over your coding slump. It will all be easier the more experience you gain with the engine and data patterns. Happy coding.