Problem with saving Asset Reference in struct in 4.13 (worked in 4.8)
I am trying to save a skeletal mesh reference inside a struct of skeletal mesh reference. A kind of inventory system.
So I a created character blueprint with a struct variable that contains a Skeletal Mesh Reference. During game, I edit the struct skeletal mesh reference thanks to the detail panel and I save that struct in a save game slot. I exit game, close UE4 editor and restart the editor. I then load that struct during game and fill my character struct variable with the loaded struct. UE4 editor in play in viewport seems to not be able to read the values saved and won't filled the struct with the Assets References (that are actually visible if I open the savegame file in a text editor). All references are blanked.
The problem is that all this was working perfectly fine in UE4.8. Now that I have upgraded to UE4.13, unreal doesn't seem to be able to read the struct from the save games slots correctly. Or not all the time because it works If I don't close the editor. It saves and loads the references perfectly until I close the editor. A workaround I found but that's not a viable option is that if I load the asset referenced in my struct with the level blueprint before loading the save game slot containing the struct, unreal seems to be able to read the values from that loaded struct. The problem is that I can't load all the assets before maybe make a reference to it in my struct, it's just not efficient in any way.
I spend hours to try to find a solution to this with my good friend google without success. I also tried to change the variable type in my struct from a Skeletal mesh Reference to a Skeletal Mesh Asset ID. If I do so, UE4 crashes when I try to save my game slot containing the struct... I thought that would have worked though because it looks like a Skeletal Mesh Asset ID allows to reference an asset that is not loaded and the Skeletal Mesh Reference might not be able to do so but I might be wrong. Anyway, like I said, if I try to use a Skeletal Mesh Asset ID variable in my struct, UE4 crashes when I try to save my struct to a slot, so I don't really know what to do anymore... I also read stuff about TassetPTR Pointers and Asynchronous loadin but found nothing linked to blueprints and C++ scares me a lot because I don't much about it...
So I hope I have been clear and that someone can please help me because it's driving me crazy. Why does something as simple as that and that was working in 4.8 doesn't work anymore in 4.13...
Basically I am just trying to assign a skeletal mesh reference in a struct during game for my character, save the struct in a savegame slot and reload that struct from the slot after I closed UE4 editor. Right now it only works if I load the referenced asset before loading the struct that references it which is not really a viable option, considering that I would like to be able to pick a skeletal mesh from a big bank of them and can't load all of them before loading my struct from my savegame slot.
Soooo... Is anyone able to save a skeletal mesh reference inside a struct to a save game slot and then load that struct properly from that saved game slot ? If so can you please help me ? Or anyone has noticed this and it's officially a bug ? Because even though I am not an expert, to me it sounds like it since it was working in 4.8...
I'm not quite sure why you're receiving this error and you're not exactly saying your process so I can't tell if you're doing anything incorrectly, but I'll explain how I put together, as it works correctly for me.
Firstly, I created a project with the ThirdPersonTemplate. I then created two assets: A struct BP (MyStruct) and a SaveGame BP (MySaveGame). In the MyStruct, I made one value and set it to Skeletal Mesh Reference and called it SkeletalRef. In MySaveGame I created a variable of the MyStruct type and set the default to SkeletalCube (from Engine Content) as it required a default.
I then set up the following actions in my ThirdPersonCharacter blueprint:
The F action creates a new save game object, casts to my custom MySaveGame class, sets the SkeletalRef inside of it to the current Skeletal Mesh of my ThirdPersonCharacter BP and then saves it to the MySave slot. The G action loads the save in the MySave slot, casts to my custom MySaveGame class and then saves it in a variable. V uses the variable from the previous action to check the currently loaded SkeletalRef and print the name.
To test this, I ran through those actions once and it ended up printing out SK_Mannequin, as expected. I then changed the ThirdPersonCharacter's skeletal mesh to Tutorial_TPP (Also from Engine Content) and saved everything and then closed/reopened the editor. I then hit play and ignored the F action as I didn't want to save again. I pressed G to load the save from the previous session and then V to output it and it continued to output SK_Mannequin.
I hope this explanation/example can help you figure out what might not be correct in your workflow.
answered Oct 14 '16 at 06:19 PM
Matthew J ♦♦ STAFF
I finally I have been able to investigate this more. I apologies for not being able to do so faster.
My computer wasn't working so well so I did a clean install Windows10/UE4.13
Matthew, you were absolutely right, I was confused by your graph because I didn't even thought of the "Split Struct Pin". Thank you again for taking the time to read my extensive post and pointing that out. I felt pretty dumb not to think about it.
I am fairly sure I have been able to reproduce what you have shown me. And you are right, it works. But from what I have tried, it looks to me like it works specifically because the asset reference you store in the saveGame is an actor that is already loaded, the SK_Mannequin, because it is used by the player. As I wrote in my original post,If I try to store an asset reference of an asset that's not in use in the level or just hasn't been loaded yet, the asset reference loads fine as long as I don't close the editor. If I close the editor, it won't.
To try this out, here is what I did:
Instead of storing a reference to the skeletal mesh that is used by the ThirdPersonCharacter, I created I a new Skeletal Mesh Reference variable in my ThirdPersonCharacter Blueprint, made it public and tried to store it using the exact same process you used.
I press play in selected viewport. I then select my ThirdPersonCharacter and set the public skeletal mesh reference variable I created to "Hands" Skeletal Mesh through the detail panel. I press F to do the whole process of saving the SaveGame instance. I then press escape and play in selected viewport again. I press G to load the reference and V to Print it's name and set the public Skeletal Mesh reference I created. That works. Now if I exit editor and relaunch it, when I press G and V again, the reference isn't loaded and nothing is printed on screen.
If I do the same process over again (saving, closing editor, relaunching, G, V) with the SK_Mannequin it totally works. So as I said in my first post, it looks like the reference is able to be loaded only if the asset as been loaded before, like the SK_mannequin used by the player (for some reason it also works if I use the Skeletal Cube, maybe because it's from the engine content, I have no idea).
Soooo.... I am still stuck on that one. Matthew, would you be kind enough to try this again ? Or anybody else ? I feel like I am close to writing a book on this ;-)
Please, someone proves me I am a total noob and just don't get it! Is anyone able to pick a Skeletal mesh Reference during runtime, save that skeletal mesh reference of a Skeletal Mesh (that hasn't been yet loaded or used in level) inside a struct to a save game slot and then load that reference from that saved game slot ?
answered Oct 31 '16 at 03:46 PM
Thank you for explaining the difference and for giving all the detail you could. I was able to reproduce this with the setup you've provided. There seems to be another bug that could be related to this that was fixed recently. I'm going to try reproducing this again after that fix's changelist and see if I get the same results. If so, I'll be placing a bug report in.
Here's the other bug: UE-37774.
answered Oct 31 '16 at 08:17 PM
Matthew J ♦♦ STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here