Saving hidden actors
I've created a collecting system, where once you pick up an item it'll make it hidden in game and I have a Boolean ticked to say it has been collected. But now I've run into the issue of trying to get this now hidden object to save its state. I try to save it in an array but once the level is loaded again, i can't seem to get it to go back hidden.
Has anyone come up with a similar system and if so how did you do it?
asked Jun 21 '17 at 06:33 PM in Blueprint Scripting
I am using the fact that as soon as actor appears in the scene, its BeginPlay event is fired.
I've created a SerializableActor derived from Actor, which overrides this event and all actors I want to serialize are derived from this superclass.
This actor also has my own overridable function Deserialize, which is being called upon BeginPlay.
Now my actors are basically implementing their specific use of the deserialization, because serialized data are just a string collection and interpretation is up to the specialized class.
Stored data are in my own class derived from GameInstance (which is singleton - so you can rely on it always).
I hope this helps. Feel free to ask if anything is not clear.
answered Jun 21 '17 at 08:49 PM
Ok. Please keep in mind that I do all my logic in C++, but I've created a mockup simplified solution which can be a bit close to what I am doing. It's untested, but should give you an idea. :)
create a structure to store persistent data - reason being Map in BP can't work with more complex type - it's simply an Array of strings (I called it TestSerializedData)
In your class derived from GameInstance add a variable ActorStates and define it as Map
create a method, which takes actor name as string and string of achieved states (those can be anything). If you go C++ route, you can instead use JSON to serialize your states in a more advanced way.
create also a getter method to query for available states.
create an Actor class called SerializableActor which will be parent to your child classes.
Continue in next post because of 5 file limitation.
answered Jun 22 '17 at 04:53 PM
In your child class override deserialize event so it handles the needs of your actor.
Whenever anything serializable occurs, simply call the serialized method.
Please note that in streaming levels you might also want to store the level actor is in because of possible naming conflicts, My own solution is actually way more complex as my superclasses serialize many states by themselves, but this should get you started, :)
answered Jun 22 '17 at 04:55 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here