How do i add a ID instance variable everytime i cloned the item

how do i add a ID instance variable everytime i cloned the item and it would like this for example

cloned item ID = 1
cloned item ID = 2
cloned item ID = 3

like this

Can we ask why you want an ID? IDs are a pain to maintain. Sometimes, they’re the best method but most of the time there’s an easier way.

to save a tree position and more cuz im making a survival game

i have a way but it take like hours to do

this is the code but my world in the game is big and it needs like 500 trees to make it look natural
and other environment stuff and it also helps the performance because i can delete an item if not on screen and spawn it again if on screen because it runs like 20 to 30 fps on phones cuz its pc and mobile game and its just six trees but the code is very long

IDK if you need to selectively add delete tree but I liked the challenge. This will load, save and selectively add trees by moving around point1 and point2. Everything is draggable. If you still want to use IDs, let me know but if the trees are all the same then you can add trees by their x,y.

try it:


Edit: I had to modify the project files. it was deleting the trees if there wasn’t saved data. So now it will start with the default trees unless you click load. Since I already posted it, I wanted to do a quick fix.

Edit #2: I added a few comments to the source project and added a check to make sure a save exists before loading from the storage.

thank you so much :+1::+1::+1::+1::+1::+1::+1:

I give credit to you i will put your name on the credits scene

1 Like