- Home /
Is it possible to start a new game after a certain point in time of a previous playthrough?
Hello,
I'm wondering if I could start my game from a point in time after the physics engine has moved my game objects a bit.
I have many blocks that roll down a hill, and I want the game to start when the blocks are at the bottom of the hill, so the player doesn't have to watch them actually roll. I think I have to write down the position/rotations of all the blocks, and then manually move them there after stopping the play test. This can get quite tedious with many blocks. Is there a better way to do this?
It's basically saving the scene as it is after the physics engine has done its part moving the objects.
Since you are using the physics engine and it is calculating the physics in real time you have to let the engine calculate the new position each frame. You could however check out Time.timeScale - it is normally used for slowmotion effects, but you might be able to set it to higher than 1 and "speed up time" (don't know if this will work though, haven't tried it).
Or you may have to check the position of each cube at a certain point in time and then save those positions in an array and instantiate the blocks when the game starts. Depending on how many blocks there are you may want to write script to help get the positions of all the blocks.
I can't think of any different ways..
I'm trying to avoid the physics engine from calculating it all at runtime, because at the moment it's lagging the game. When the blocks stop moving the lag settles, so that's why I want it the game to just start there. There is no way to just "save" the scene as it is at that certain point in time?
Totally out of the blue, but maybe it works. Start your scene and pause it at the right time. Don't stop it, just pause. Then save the scene. No idea if this actually works.
No, sadly that doesn't work. I've tried before asking, heh. That would make it too easy!
Answer by nsxdavid · Feb 25, 2013 at 04:20 PM
Using physics to place stuff is a feature sadly missing from Unity. I had such a feature in HeroEngine because it was so useful.
However there are tools in the Asset Store that let you maintain stuff that happens during play. For example, Editor++ comes to mind. Using that plugin you can then select all the cubes and have it remember their transform during play. Then stop and apply what was remembered and they'll be in their settled (at the bottom of the hill) location.
This is far easier than doing it manually with pencil and paper. But if you don't want to use a 3rd party component like that, you could write a script that on some input (say a button press) records all the important transform info from the objects you are interested in to a file. If you give them a unique name, then it would also be straightforward to read that file back in with yet another script (editmode this time) and apply the updated transforms back to said objects.
Editor++ looks like exactly what I would need, but is there a 3rd party software that does almost the same thing but free?
If not it looks like writing all transforms into a file and then reading it out again would be my best bet.
Someone stated before that copying all objects during play mode and then pasting it would be a good idea. Can you explain why this doesn't work? Unity always crashes for me when I try pasting the gameobjects in. $$anonymous$$ight be too many things being pasted at once perhaps.