- Home /
How to apply Undo Redo mechanism on line renderer
Hey guys, I am creating a painting application. So based on mouse position line renderer will draw the lines. But i am unable to apply undo and redo buttons on line renderer. I have no idea how to do that. Please help me guys i am a beginner.
Answer by Glenn-Korver · Jul 04, 2021 at 09:58 PM
To have any kind of undo / redo system its likey best to startoff with keeping track of the inputs.
So a basic start would be, anytime you add a point to the linerenderer you also store it in an seperate array. Then when you undo you remove the latest point from your linerenderer, end then if you hit redo you go one step forward again and grab it from the "seperate array".
Perhaps you will spawn multiple line renderers, like each is its own stroke, in this case you will also need to keep track of if the points are part of the same stroke / linerenderer. Each stroke/linerender you create should then also be stored in an array/List where you can target the most recent / last stroke until its out of points. Redo would then need to recreate the "removed" linerenderer if needed.
The exact implementation would be to specific / case by case. But the core is you need to start tracking anything relevant to what makes up your drawings, in order that they happend, so you can step back / forward. or even throw away all the visuals and recreate you current state based on the info you have.