Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: richardh on May 02, 2018, 09:18:38 AM

Title: Advice on save/load
Post by: richardh on May 02, 2018, 09:18:38 AM
Hi, again!
I have a working prototype of a VR game (actually it's a simulation rather than a 'a game'). It's for single player and allows the player to construct a model on a big table using small parts to construct an entire model. At the start the table is empty and by picking a large variety of parts and placing them on the table the player ends up with a purpose designed model they can then interact with. The model is therefore constructed using many bits (gameObjects). These objects are copies of the chosen parts selected by the player.

So... The empty table is the start. The table can have from a single item (picked by the player) right up to many hundreds of items (maybe even a few thousand). Each item will be a copy (clone) and also a clone of a clone of a clone...

This is how far I've got and the next thing i need to approach is a way to save these objects positions & rotations so that the player can save and return and load the scene to continue/edit the model.

I have just bought Smooth Save for Playmaker. But I have also noted Easy Save too.

What would be the best method to save each object's position and rotation? Would Smooth Save work for me? Is it possible to save and load the pos/rot of a clone?

Is it possible to save the locations and rotations of so many Objects? (in theory, the game allows for unlimited amounts of model parts to be added to the table (unless I code a limit of say 10,000 objects). Is this amount okay or unfeasible?

I will post a short YouTube vid of the prototype a bit later to give an idea of what the game (simulation) is about.

thanks in anticipation for any help/replies/advice.
ta
R
Title: Re: Advice on save/load
Post by: djaydino on May 02, 2018, 01:51:41 PM
Hi.
i think best is to use arrays and save the arrays.

I Do not know if they can be saved in smooth save,

But i do know that array list can be saved and you can find actions for it on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181)
Array list is a more advanced array that can also be found on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181)
Search for 'array maker' and 'easy save'
Title: Re: Advice on save/load
Post by: GonerGames on May 02, 2018, 02:32:46 PM
Easy Save is amazing.
The new Easy Save 3 auto save might be what you are looking for.
In short:
Install Easy Save
Go to Assets -> Easy Save 3 -> Enable Easy Save for Scene
Create Parent Object -> Add ES3 Autosave script and enable Save Children

This will auto save at scene end (quit) and auto load on scene start.

From there you can tweak your needs.
Not sure the performance hit on loading 10,000 objects would be  :)

Thanks

Title: Re: Advice on save/load
Post by: richardh on May 03, 2018, 09:25:24 AM
Thanks for the great replies, guys.
If Easy Save can be integrated that easily then I will certainly look at buying that. Smooth Save looks very similar so I will see how far I can get with that. Arrays... Not sure I'm knowledgeable enough to use arrays - I know I should investigate arrays if I want to expand my game making skills!

So, in regard to saving prefabs (GameObject copies), it is possible? Oh and also, This game is VR but I assume the same rules apply with regard to saving and loading?
Title: Re: Advice on save/load
Post by: richardh on May 03, 2018, 12:50:38 PM
UPDATE:
Well, I bought Smooth Save and after a couple of hours trying I gave up! Totally stumped.
So, I bought Easy Save and tried to follow the instructions, tuts, forum threads etc. After a couple of hours trying I gave up! totally stumped here too!

I think it's because i'm trying this on a VR game and perhaps it's not compatible?

I haven't even got to grip with ANY of the examples in either package as the examples are not working examples but simple text descriptions which mean nothing to me.
@GonerGames I followed your advice but alas nothing worked, nothing happened, nothing saved.
Do I need to build the scene to see if it works?

Usually, I can work things out by delving into the example scenes of a new asset (if they have them) but in the case of Smooth Save and Easy Save, this is not the case as the examples are not actually working examples that can be dissected.

Totally and utterly lost and haven't a clue how to proceed!

@GonerGames
Quote
"Go to Assets -> Easy Save 3 -> Enable Easy Save for Scene
Create Parent Object -> Add ES3 Autosave script and enable Save Children

This will auto save at scene end (quit) and auto load on scene start."
Could you elaborate on this because nothing saved for me after following your instructions? there must be a bit more to the setup than this? :)




 
Title: Re: Advice on save/load
Post by: GonerGames on May 03, 2018, 03:14:12 PM
Sorry Richardh,
I loaded up a fresh scene and the latest version doesn't work like that. Sorry for the bad advice. So now let's fix it :)
Here is a video. Sorry for the background noise.

Hope this helps.
https://youtu.be/Kk5pYeRvqiw (https://youtu.be/Kk5pYeRvqiw)
Title: Re: Advice on save/load
Post by: richardh on May 03, 2018, 04:08:08 PM
@GonerGames
Many thanks for taking the time and trouble to create that tutorial. I will work my way through it and try to replicate what you have done which should give me a bit more to go on as I try to work out how to save and load my game scene.

Your example is using prefab cubes which are added to the scene at random positions and random rotations. My prefabs are also cubes but once they are in the scene the player can reposition them and also rotate them (basically edit their position and rotations). If they change these things would your method (in your tut) update the positions & rotations upon exiting?

Title: Re: Advice on save/load
Post by: GonerGames on May 03, 2018, 09:51:13 PM
The tut was just to show that Easy Save will save the position and rotation of the prefab objects. Just make sure you have a button or timer that will fire off a Save like the one on the Load Scene Button. This will then save all the prefabs that you've registered. In the settings under Windows -> Easy Save 2 Window -> Settings, you can choose to have it auto save on Application Quit, Application Pause or None.
I usually have this set to none so that I can control the saving and loading manually.

Title: Re: Advice on save/load
Post by: stvbabb on May 04, 2018, 02:25:01 AM
Hello,

Thanks for that video! It really helps! I've been trying to figure out Easy Save with Playmaker and I know it's really straight forward, but I'm struggling as well.

Any advice for creating save slots for the player? I see in the demo for Playmaker that loading from save slots is there, but saving to a specific save slot?

Like the player at continue their game from save slot a,b,c, or d? And then, in game save their progress to that save slot.

I know array making is going to come in to play here, but I just can't seem to get this.

Thanks,
Steve
Title: Re: Advice on save/load
Post by: djaydino on May 04, 2018, 02:18:01 PM
Hi,

I am working on a tutorial video (not using auto save) , i will try to upload before Wednesday.
If i did not reply by then, please bump this thread :)

@stvbabb
Arrays are very useful here and it will be very hard without them.
Array are not that hard to understand, i will try to explain a little when i make the video (or make a separate video for it)

To save in different slots is easy to do with easy save, as it uses references.

Save each array or other variables in a reference.
Name a reference for example : SlotAvariableOne / SlotAvariableTwo / ....
Then for slot 2 do the same but then use SlotB

To save or load you can set the string variable on the reference to select which slot.

if you don't understand, let me know and i will make a tutorial next week :)
Title: Re: Advice on save/load
Post by: stvbabb on May 04, 2018, 02:26:57 PM
That would be really helpful! I'm just running into more and more problems with this asset.

I just don't understand it. If you had a video that would be really cool.

Thanks,
Steve
Title: Re: Advice on save/load
Post by: richardh on May 04, 2018, 02:43:22 PM
Yeah, I'm still none-the-wiser with my save/load query. If anything I even more confused now. I communicated with Christopher (smooth save) who kindly offered some advice but alas it was way over my head.

An issue I have is that the objects I want to save/load are actually modified prefabs - they are clones of prefabs but I've used Playmaker actions to add children and to change tags so they are no longer original prefabs.

I truly have no idea how to proceed with this. Desperately need an 'idiots guild'!
Title: Re: Advice on save/load
Post by: stvbabb on May 04, 2018, 03:27:27 PM
Yeah, me too. I'd like to consider myself competent with lots of Unity stuff - but this has me totally confused.
Title: Re: Advice on save/load
Post by: djaydino on May 04, 2018, 05:08:23 PM
Hi,
That makes it a lot harder as you can not save objects.
What are the exact changes?
is it only adding different child objects or is there other 'data' changed (variables, colors, other things)

Maybe for this situation you might need to look into xml/json and use Datamaker.
Title: Re: Advice on save/load
Post by: richardh on May 04, 2018, 05:59:18 PM
No, the only changes from the original 'prefab' to copied clone is the tag and the addition of children along with the new position and rotation. There are no data changes. I can (and probably will) make the original objects proper prefabs. At the moment the original objects are the cubes in the scene that the player is able to interact with (VR using right controller to touch and copy the object)
Basically, you (the player) are ina  VR room that contains a large square table and an assortment of cubes that you can touch with a VR controller to copy the touched object which you hold (with the controller) and then you're able to position the NEW (copy) object on the table and also rotate it. Do the same with another copy of an original cube until you have created a large model on the table (made up of lots of these copied cubes). At that point I want to let the player obviously save what they've created so they don't lose it after the end the game and can fire up the game again to continue with the model (they can edit/move the cubes/rotate the cubes/delete the cubes etc and save them all again. etc)

I've built all this apart from the save/load part which is the next task to do - hence why I'm asking for help as this bit is beyond my skill level.
I can post a vid of the scene if it helps.

Another thing I wanted to try to do is to give each of these copied objects an original name rather than [cubeA](clone)(clone) etc. Would giving each object an original and new name make it easier to save/load? I suspect it would.
thanks
Title: Re: Advice on save/load
Post by: djaydino on May 05, 2018, 06:09:42 PM
Hi.
How many children will there be maximum on an object and do they also have different positions/rotations?

Are the blocks with children making different forms (like 2x2 block, 2x4 block and so on)
if so you could build then and make prefabs from that, in that way it will be easier to setup (and probably faster loading)


Naming would not really make it easier to save/load nor make it harder (you would need another array to save the names or when using datamaker, add it in the list) on a little more work.

if you can show a video or post some images or post the scene would be helpful
You can also pm them if you do not want to do this public.
Title: Re: Advice on save/load
Post by: richardh on May 05, 2018, 07:33:09 PM
@djaydino
The children that are added to the blocks are what I call phantom cubes - they are identical sized cubes to the parent cube and are literally surrounding the parant. So I have 5 phantom cubes imme3diatley surrounding their parent on all sides apart from the bottom (bottom phantom is not needed). The job of the phantoms is to be hit by a raycast from the VR controller which will get the position of whatever phantom it hits. This phantom position (phantom is invisible in the scene - mesh renderer off) will be used for the placing of the next cube. The player will pick up (copy) another cube and point his controller toward the already placed cubes. when the raycast hits a phantom it will activate (mesh renderer on) and the player will decide if he wants to place his next cube there. Controller trigger press will add the next cube to the phantom's position.... and so on.

So there are 5 children given to the new cubes (copy cubes) which act as position placements for subsequent cubes. Their position is always immediately next to the parent and there is no need for these children to move position or rotate once they are added to the scene.
If the parent cube is deleted by the player then so are the children. if the parent cube is picked up and replaced by the player then the children are destroyed (on pickup) and created again (on placement). If the parent cube is rotated (left/right) or spun (clockwise/anticlockwise) the children remain static (no need for them to move or rotate).
The children are not visible in the scene (mesh renderer off) but are used purely as location positions for more cubes.

I suppose that, on save, the phantoms (children) could be destroyed so only the original cube (name, pos & rot) are saved. And then created once the game loads again?
Would that make things easier?


Hope I've explained that okay. I can post a short vid if it helps.
ta
Title: Re: Advice on save/load
Post by: djaydino on May 06, 2018, 04:54:27 PM
Hi,
I think i understand.

Destroying objects is expensive and leaves garbage, so i would consider to change this.

Instead you can have these phantom boxes preset on each side and activate/deactivate them

Or another way could be to place the triggers on the edge of each side.
then use an indicator, here you can see what i did, i will try to make a video before Wednesday.

Title: Re: Advice on save/load
Post by: richardh on May 06, 2018, 07:16:47 PM
Not sure I follow that video. I'll rewatch it and see what you're doing. The triggers you're using are sort of like what my phantoms are doing. How would you place the next cube(s) exactly in the correct position using this method?
I admit that my setup for new cube placement (using phantoms) is not that elegant and will have to be changed but the real issue is how to save and load those already placed cubes in the scene. Once I nail that I can redesign my 'phantom' placement method with something that doesn't involve destroying. Although, theoretically, destroying objects should not play a huge part in the game.
thanks for the help :)
Title: Re: Advice on save/load
Post by: djaydino on May 07, 2018, 05:15:06 PM
Hi.
By designing them this way you would only need a single prefab, and then it is easier to save/load the positions from those prefabs.

i made a working system now (with multiple colors)with save and load in it.

To position the blocks i parent the 'indicator to the select block/side and for each side the position is set locally from the selected block.

I will try to make a tutorial video in the next days, here is a preview on what i made :

(https://i.imgur.com/6bgUsWb.gif)
Title: Re: Advice on save/load
Post by: richardh on May 07, 2018, 05:26:08 PM
What you have done there, in probably half an hour, took me 2 weeks! feel very inadequate!
Yes, please, make a tutorial if you can. I really need help on save and load.

thanks for your help and time, sir!

Edit/Update:
Here is a link to a quick and dirty YouTube vid of the project prototype I have created so far:
https://www.youtube.com/watch?v=mGIboQZC5-I&t=19s (https://www.youtube.com/watch?v=mGIboQZC5-I&t=19s)
Title: Re: Advice on save/load
Post by: djaydino on May 08, 2018, 04:11:34 PM
Hi.

Ah thx for the video.

For this i would use pooling and store the object names or pool names in a addition array and not an array for each object.

i will adjust my sample and try to make a video tomorrow.
Title: Re: Advice on save/load
Post by: djaydino on May 10, 2018, 07:06:41 PM
Hi.
Sorry i did not have time to make a propper tutorial, but i did record a video explaining what i did.

Title: Re: Advice on save/load
Post by: richardh on May 11, 2018, 06:23:34 AM
That is excellent @djaydino
I will watch that vid and try to apply it to my own project.

Is there any chance of downloading the scene you created in the vid? So I can dissect it at my leisure as I watch and learn the video?

I will put a nice donation in your donation box ;)



Title: Re: Advice on save/load
Post by: djaydino on May 18, 2018, 05:16:07 AM
Hi.
Did you get it to work?
Title: Re: Advice on save/load
Post by: richardh on May 19, 2018, 06:57:29 AM
Easy Save is amazing.

No, I've not had a chance to properly delve yet. Had a look but I will need to really take time to work out what you've done.