# How to Undo and Redo?

**URL:** <https://forum.babylonjs.com/t/how-to-undo-and-redo/7050>\
**Category:** Questions\
**Tags:** material\
**Created:** [November 18, 2019, 2:58am UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050 "2019-11-18T02:58:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [November 18, 2019, 2:58am UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/1 "2019-11-18T02:58:08Z")

</div>

Hi,  
I am having trouble saving history after every change eg move, create, delete, … with lots of objects in one or many scenes  
Has anyone ever done that work share the idea? Thank you very much

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [November 18, 2019, 4:47pm UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/2 "2019-11-18T16:47:55Z")

</div>

Hello is it with regular babylon.js or using the editor?

---

<div class="post-metadata">

**Author:** ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://forum.babylonjs.com/u/adam)\
**Post date:** [November 18, 2019, 6:07pm UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/3 "2019-11-18T18:07:09Z")

</div>

Look up “command pattern”.

Here is a javascript example I just found:

> **[JavaScript command pattern for undo and redo](https://developer.s24.com/blog/js-command-pattern-for-undo-and-redo.html)**
>
> Being able to undo and redo actions is awesome! I already knew the command pattern, but as always everything is different in JavaScript. After figuring it ou...

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [November 19, 2019, 3:24am UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/4 "2019-11-19T03:24:08Z")

</div>

I’m creating a tool for people to draw 3d objects, move, change colors and textures, … in scenes with regular babylonjs.  
So I’m looking for ways to save history of what they’ve done or any way to help me undo and redo those actions.

eg: the object is created and edited a lot of things then deleted so how to save it perfectly to undo it back to before it was deleted?

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [November 19, 2019, 3:38am UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/5 "2019-11-19T03:38:56Z")

</div>

Thank you for reply. But I am having trouble saving, not the undo and redo processes

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [November 19, 2019, 8:54am UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/6 "2019-11-19T08:54:07Z")

</div>

> [@HUY\_HOANG](#):
>
> So I’m looking for ways to save history of what they’ve done or any way to help me undo and redo those actions.
> 
> eg: the object is created and edited a lot of things then deleted so how to save it perfectly to undo it back to before it was deleted?

> [@HUY\_HOANG](#):
>
> Thank you for reply. But I am having trouble saving, not the undo and redo processes

Sorry but to me these two statements, along with the title, appear contradictory. If you are not having problems with the undo and redo process then you understand the command pattern as suggested by @adam’s link and the command pattern saves the history.

This means I must be misunderstanding what you mean by **history** and **save**. What exactly is contained in the **history** and where do you want to **save** it?

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [November 19, 2019, 3:26pm UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/7 "2019-11-19T15:26:11Z")

</div>

sorry english is not my language. I mean, I don’t have a problem with the way undo and redo handle the order, but I have trouble saving obj and restoring it with all the changes like color, textures, position, rotation, etc. …

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [November 19, 2019, 4:03pm UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/8 "2019-11-19T16:03:34Z")

</div>

Do you mean save it as a file in a folder?

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [November 19, 2019, 4:24pm UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/9 "2019-11-19T16:24:43Z")

</div>

I want save it in the array  
Every time I call the “undo” I subtract the location by 1 and “redo” I will add the position by 1

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [November 19, 2019, 4:32pm UTC](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/10 "2019-11-19T16:32:56Z")

</div>

As far as I can see the suggestion by @adam in [How to Undo and Redo?](https://forum.babylonjs.com/t/how-to-undo-and-redo/7050/3) sets up the correct structure for saving your commands and and moving through them with undo and redo. At this point there is little more I can do other than referring you back to this and asking you to read the article carefully and double check it does not do what you want.

If it does not do what you want please explain why it does not.
