Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Spawning, Saving and Loading Procedurally Generated Prefabs

Discussion in 'Scripting' started by tylermv, Feb 4, 2020.

  1. tylermv

    tylermv

    Joined:
    Feb 26, 2018
    Posts:
    2
    Hi there,

    I'm currently working on a game that procedurally generates planets and the player can "discover" these planets when they get to the end of each level. Once a planet is discovered I want to be able to save it and load it into a map so the player can keep track of the planets they've discovered but also revisit the planet if they'd like.

    The problem I'm having is the saving and loading of the planets. I've gotten as far as being able to get into the level, generate a planet, save the planet using serialization, load it onto the map. My happens when trying to create a second planet, save it and load onto the map and have multiple planets all with their own sizes and colors etc...

    I've done a lot of Googling and watched a number of tutorials on serialization and scriptable objects but I don't think they've solving my problem. Any direction on this would be greatly appreciated.
     
    Last edited: Feb 4, 2020
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,123
    Editor and prefab utility is not available during runtime, if I remember correctly asset database is readonly and it's not possible to write anything there. If you want to save some data during the game you need to create save file and store your data there. You can use JsonUtility or custom serializer or tool from asset store.

    If your planets are quite simple and all of them got the same properties I recommend you to create custom serializable class and use JsonUtility - it can serialize references as well. Anyway I think it would be good start.
     
    tylermv likes this.
  3. tylermv

    tylermv

    Joined:
    Feb 26, 2018
    Posts:
    2
    Thank you this at least gives me a new direction to look. Appreciate your help.