I’m looking for a way to save an actor in game to a list (I think this should be a structure list).
Right now I have a level with an actor where I can add object to while playing the game. I want to save this blueprint actor with the objects that I added to so that I can grab the item later with a widget.
I tried to setup a structure list with pre-build actors in it and I’m trying to add my custom build actor to it in game. So far I tried to follow this tutorial: UE4 Save/Load Tutorial with Structures - YouTube
But the problem I’m getting is that this one is built on the already existing variables in the structure list.
What would be the best way to add an actor to this structure list?
Or is there an other way that I should try?
Saving actors directly is quite tricky- you’d need to do some not-so-simple c++ coding to get it done.
A simpler option would be to create another structure for each actor type- in that structure you’d save the class, transform, and any other important variables you want.
Then, when loading, you could reference that struct to create the actors and load their data.
This topic has been moved from International to Programming & Scripting.
When posting, please review the categories to ensure your topic is posted in the most relevant space. Hopefully, this category change will help you (or other devs) to get an answer.
Thank you,
I don’t think that would be an option unfortunately as this can be a lot of different actors that are all different as they are custom build by the player.
I have a level where you can build custom weapons from scratch by adding different attachments to it (all blueprint attachments). Then I would like to save this weapon that is built by the player so he can play with it.
So I was thinking I player can save this custom weapon to a structure list as an actor so that he can play with it later.
@Crossroad1000 You need to write a function that will serialize the parameters that dictate how the object it made (what components with what parameters).
In essence like an ingredients list that can be used to rebuild the object during runtime.
This can be either saved to a struct or json string and pushed to your savegame file for later use.
p.s Save only class soft references or class names not the object itself
From what you’re telling me I can definitely see a solution.
Seeing as you said “all blueprint attachments” I’ll assume you’re using an actor for the weapon, spawning other attachment actors and attaching them using the attach actor to actor node.
To save something like that, you could do something like this:
Of course, if you’re handling it some other way it may be different. If this doesn’t help, please respond with some images showing how you’re doing it.
Yes this was what I was looking for.
The only problem I now have is that some of these attachments contain variables (changed by the player) that I want to save too.
Make sure you’re including the variables that every attachment has in that struct.
I would probably recommend saving a string to string map in the struct, and manually saving all the unique variables to it. For example: you could input a key of “Health” and have the value be “100”. This would be in string form, but you can use a switch on string node to then manually parse it. When saving the attachments, just call a save function on them, passing in the struct as reference. They can then modify it with their variables.
If you’re comfortable with C++ then using objects would be better since they can use inheritance. Saving those objects is the trickiest part though. If you want, I can send over the code that would do it.