Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Customization through exchange of child objects and progress saving

Discussion in 'Scripting' started by marzipano, Jul 2, 2020.

  1. marzipano


    Dec 27, 2019
    I'm pretty new to Unity and still figuring out how Game Objects are referenced and accessed. So far I've been successful in narrowing down the problems I'm trying to solve, but now I need some advice on what would be best practice. I'm not providing any code, nor am I looking for specific code snippets (if you happen to have something in mind, I would be glad if you'd shared it):

    I'm having a main game object and my idea is to change its appearance by swapping its child objects with other models (upgrading the game object). I've found a script that achieved that (well, not entirely. I managed to add a new child, but the old one didn't get destroyed..., but this is something that could be solved, I guess).

    Now I want to do a game where you constantly have to start over from the beginning, but keep the progress you have made in order to go farther each time.

    My first idea was to do a retry button and just reload the scene, but then everything was set to the original state and all progress was lost. I've found solutions for static variables, DontDestroyOnLoad but this didn't really work. Yet I'm seeing a few different approaches, that I would like to test:

    1. Not reloading the scene at all, but instead just setting the Game Object's location and rotation to the starting point (this would only work for 1 Level, which would be fine for now)

    2. Loading the Player Object just once in a Scene which will never be visited again.

    3. Loading the Parent Object in each scene and "fetching" the right childs. Let's say my Game Object has 5 parts that can be upgraded in 3 Steps. So I was thinking about an array that would store the values of the current upgrade level of each part and load the corresponding models.

    Can you tell me, from what I have provided, what would be the best approach here?

  2. raarc


    Jun 15, 2020
    you can look into serialization and create a save load system. You can save the progress you want to keep when you die and then when you restart the scene you load from the serialized file whatever information you want to be kept.