Saving hidden actors

Sorry to sound like a complete noob, but would it be possible to have some screenshots of your blueprints? if you don’t mind, I work better when i can visual see what is happening.

Hi There,

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?

Regards
James

Hi,

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.

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. :slight_smile:

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

201107-f06.jpg

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.

[contd]

In your child class override deserialize event so it handles the needs of your actor.

201110-f05.jpg

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, :slight_smile: