I have build some cube and I have two button , the first one is Delete Button and the second one is Undo Button. when I deleted each cube I want to get the cube back when I click on undo button.I don’t know How can I do it, is it possible to help me to do it?
this is my PG : https://www.babylonjs-playground.com/#VKBJN#892
This is more a general programming question than a question related to how Babylon works. There are a few ways you could do this, but the basic concept is to keep a record of the state in your app and then access this recorded state as necessary. By state I just mean data, in this case you would keep a record of the meshes that you have in the scene. Every time you update the scene, like when you delete a mesh, you would update this record. The record can be a simple array. Clicking “undo” in your app then would mean looking at the last value in this record array to see what meshes were in the scene at that point. You would then update the scene using the data in that history. In your playground I see you are using instances, so it seems to me that you should create an array of objects, each object representing a snapshot of all the instances and their positions. Every time you delete an instance, add a new object and delete the oldest one. Does that make sense?
Something that might be of interest to you is the new “delta recorder” in version 4.2.0. I have never used this, but this seems to have implemented this sort of scene history for you: Apply delta changes to a scene - Babylon.js Documentation
Thank you so much for your recommend.