Hello. I am making a FP horror game and I want to save different actor data, ex. the door transform and keycard transform in an array. I want to load them in to their saved position and if the item was interacted with (via InteractInterface), then destroy that actor
I am 50% there, as the save function and load function works for the player, but not the array of actors. It saved the location, but on loading the slot it teleports all object to the player position, and not their original position.
So the problem here is that “GetAllActorsWithInterface” much like any of the “Get All” nodes, does not return them in a given order. Because it knows this, I believe it does a failsafe of some kind. What you need to do is save the Out Actors Array into the SaveGame as a variable. Then Save the actor transforms using that input for the ForEachLoop, and when you Load game use THAT instead of “Get All Actors with Interface” on the load, so the list order is identical and then it will match the array of actor locations.
i would use a base class instead of an interface instead.
interfaces are very limiting.
in such baseclass you can add functions for load/save.
and also variables (which in usual terms you can’t put in interfaces) for stuff like positions and interacted.
then you can call load/save of any actor without having to deal with all that stuff.
i think it will be helpful in the future.
also, instead of saving all actors to a variable, which could prevent them to be deleted, (unless you use a weak reference, but then you need to check validity), i would recommend changing the actor location into a map, and using an id as index, maybe the actor’s name will suffice (use the Name type not the String, since is much more performant on comparisons and lookups).
but i really recommend the baseclass one.
as it keeps all stuff loading/saving in one place.
you can even make it overrideable (virtual) so that child objects can add extra functionality specific to that class, or handle specific details.
maybe one class saves an extra variable, maybe a class has to do something to reset, etc…
which you can’t easily do with the other method.
and you’ll keep adding variables and variables to the game state.
(but if you really really wanna go through the game state route. please consider using a struct to store all data)
Hello! Thank you for the responses! The reason it is an interface is because that is what calls the Interact function after clicking the IA_Interact key. I could probably change this around, but how would I go about changing around this because I am pretty new to UE and kinda suck at blueprints. Thanks!
(i’ve edited my previous post btw).
inheritance is a really basic concept, so you’ll benefit from learning it.
it’s super easy. you just create a bp child of actor, and put a name to it.
then open your actors, there’s a button for class settings, then change the parent actor. that’s it.
inheritance is much more powerful than interfaces on some places. and i use it way way more.
though now that i think about it, you might still need to store that info on the savegame.
so you might still need to add a struct to keep the data.
so i would do this:
create a struct for saved data with fields : id, position, interacted. MyStruct
on the base class have a function GetSavedData, returns the struct MyStruct, filled.
also have a function GetId
also a function LoadData with a MyStruct as param
in the game state:
the code you have now will be pretty similar. but you can use getallactorsofclass, which i think it’s even faster than withinterface (since it implements buckets, wereas withinterface does not yet (afaik)).
when saving you iterate all objects, get id, get that from the saved map, if it exists, you call Object->LoadData(struct)
when loading you iterate all objects, get id, call GetSavedData(), store the struct in the map with the id.
you store a map with the id as key, and mystruct as value.
Hey! I have tried using get all actors of class (class: Actor) and all the objects I want to save are Parent class actor, but it throws a PIE: Error: Blueprint Runtime Error: “Accessed None trying to read property CallFunc_Array_Get_Item” when setting the actor transform to the data that is run through a get array.