sending bool toJson

I am serializing bools for saving the state of game objects.

Everything is working correctly but if the game object is not active the json file isn’t created for that particular game object.

I have the same script on about 20 game objects. when they are destroyed I set them to false with the SetActive function. The only files that write to disk are those that are still active. the ones set to false do not send the file.

When the objects are destroyed I set the bool to false then send it when the escape key is hit.

Do I need to send that bool to another script to track it because the game object becomes inactive as soon as it is destroyed?

I changed it to sending the json file OnDisable…and it works.

Is that best practice?

Best practice for saving is pretty up in the air. Having a manager script to understand the state of all 20 gameobjects, rather than having them manage themselves would generally be easier to control/more performant. You can then save “opportunist” when the player opens an menu or does something a little less framerate intensive, and/or do it off thread. You just want to be careful not to terminate the process if any threads are still active or you could mess up your save files.

2 Likes