how do i recreate a destroyed object

i am building a mazemaker game and so far its working really well. i recently am attempting to add gates but in order to remove switches i have to destroy them (unless there is a better way). but when i want to put a switch back in the spot i removed one from it throws an error

what should i do to fix this?

What does the code look like where that error is getting thrown?

Have you tried using the object as a prefab? I had the same problem with my projectile, where, when my test-platform deleted itself, my projectile wouldn’t create the platform anymore. Having a gameobject (hidden) that creates your prefab-objects after they’re deleted might help. Either that or hide them after they’re “destroyed”. (Not really destroyed, but actually hidden, ready to be used again)

nvm i figured it out