- Home /
how do i commit changes in test mode?
i see that in unity, you can make changes while you're actually in runtime, but how do you commit the changes so they stay when you're finished?
This is actually easy. Don't run test in full screen so u can see inspector values. When you set the inspector values to what you want, right click on the component in the inspector, then click "COPY CO$$anonymous$$PONENT". When you exit playmode and are back in the editor, right click on that component again in the inspector, and click on PASTE CO$$anonymous$$PONENT VALUES. Done.
Answer by chetanisinanand · Jul 06, 2013 at 09:11 PM
Easiest Way:
Enter play mode,
Adjust your values,
Right click on Script > "copy Component"
Exit play mode,
Go to original prefab > Right click on Script > "paste component as values"
And you are Done !
Accepted and voted up your answer since it is the same as $$anonymous$$e, but more easily understandable. Welcome to the community. :)
Hi, does anyone know if this can be done via Editor script? Like adding a button to an editor script and when the users clicks it , the current values are automatically committed?
@avalonsutra: This answer links to a CopyInspector script that automates the process. See latest code here. (It's from 2013, so it may need updating.)
This is great but beware with (at least) particle systems, as doing this will overwrite any textures set in the Render tab.
Answer by Mijdax · Feb 05, 2015 at 12:41 PM
If you had several changes in the editor you could also select all objects that have been changed. Copy them while you are in playtestmode, end the playtest mode and than delete the old stuff that has been reseted by Unity and finally paste your copied stuff in there. They will stay like you copied them in playtest mode.
This method is WAY better if you went ham editing lots of objects and didn't realize you were in play mode.
Warning this method can be VERY BAD for your project (because of prefabs, object modified by other during the play...). Apply this method with caution, for Level design or simple object only
One example where this can be bad is if you copy a monster that lost half his hp during the play well when you copy him back his new movespeed that you wanted to copy is there but he is also gonna start with half his hp now you have to fix it back to full.
that is not the exact solution. Because if you copy your prefabs in playmode and paste them in editor mode they turn into regular game objects unpacked.
Answer by DaveA · Jan 21, 2011 at 09:53 PM
This may help: http://answers.unity3d.com/questions/1657/best-strategies-for-not-accidently-editing-whilst-still-running
Answer by eelstork · Apr 24, 2017 at 12:22 PM
You can turn an object (and all sub-objects) into a prefab whilst in play mode, which effectively saves all the changes you made to said objects (and sub-objects) After exiting play mode replace said object by the prefab and you are done.
I don't recommend this as a "quick fix" to the "Oh shucks I was editing while in play mode"; I do recommend it as a solution when play mode feels necessary to make specific changes.
While this solution won't fit every need, it's relatively selective (does not save ALL changes) and more powerful than just copy-pasting a component onto itself.
Why is it more powerful than just copy-pasting component onto itself? I would guess both methods end up with a serialised-then unserialised version of the GameObject in the scene hierarchy.
Copy-pasting component values works only for one component; if you have changed several objects or several components in just one object, you can't use that. In this respect my answer is similar to @$$anonymous$$ijdax and the benefit was noted already, by @Noah Dyer. Unlike @$$anonymous$$ijdax though I suggested that you can turn objects into prefabs. This gives you more flexibility (for example you might save several snapshots) than just replacing the objects. You are correct that the underlying mechanism (serialization) is the same. With reference to the solution suggested by $$anonymous$$ijdax, @N00$$anonymous$$$$anonymous$$RAD correctly pointed that references external to copied objects are broken (which isn't always an issue); same applies to my answer.
Answer by Bob5602 · Jan 21, 2011 at 07:29 PM
You cannot. The changes you make while in "play" mode (or runtime as you put it) are only there for you to fool around with the settings during gameplay. All those changes are wiped when you stop the game. In order for them to stay, you just need to make the changes while not in runtime mode and save the scene.
thanks. i was hoping that there was just some button you could press that would save them for later.
Sadly not. Thats why its good practice to make sure you're not running the game while you make changes, or else you run the risk of losing a lot of time / effort when they get cancelled out.
One "cheat" is that you can copy a component, go out of play mode, and then paste in the component values.
Your answer
![](https://koobas.hobune.stream/wayback/20220613100453im_/https://answers.unity.com/themes/thub/images/avi.jpg)