Game Reset? (SOLVED)

I’m making a prototype and am trying to figure out a way to delete everything in my scene and then replace it all like it was originally so the player doesn’t have to rerun the python file.

I was thinking of creating something that delete my Main game class and then created a new one, but that doesn’t seem to work.

I also trying doing a for loop that deletes everything and then re-initialize my Main game class.

Any suggestions?

What I had to do in my game was moving all the inicialization to a function, then I call that function again to restart. You just have to make sure in that function you reset every needed variable or state, maybe you’ll have to kill some tasks too.

Basically, if you want to build an automatic deletion of your game class instance, you have to iterate through all of its attributes, and destroy each attribute using its class’ destructor, not the usual Python’s del command. So, if you need to destroy a NodePath, use removeNode(), for DirectObject, it’s ignoreAll(), for OnscreenText, it’s destroy(), and so on.
Of course you also have to iterate through all sequences stored in any attributes, e.g. attribute which is a list of some nodepaths.

I’ve created one and used there :

Look in and
You just need to strip it down a little and adjust it to fit your main game module.

Thanks for the advice

I just went through all the elements in my game and deleted them accordingly. There weren’t that many surprisingly.