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. Dismiss Notice

save terrainData into the file at the runtime and load it

Discussion in 'Scripting' started by none3d, Apr 20, 2021.

  1. none3d

    none3d

    Joined:
    Mar 4, 2021
    Posts:
    156
    hello
    I tried to assign the textures to the terrain and insert the trees on it at the runtime
    But after closing the game and reopening it, there is no trace of what I did last time
    Is it possible to save the terrain data into the file and load it in the next run?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Changes to assets or scenes made at runtime would have to be replicated again at the next runtime. The Unity Editor functionality to save scenes and assets does not exist in a build. So you'll need to record whatever you're doing to your own save file, and when you load the save file you use the data to do the same changes to the assets or scene again. There's lots of threads on save game systems which cover a lot of this in more depth.
     
    none3d likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Everything that Uncle Joe says above is spot on. This is just basic load / save and oceans of digital ink have been splashed all over the planet about how to do it. It's a very well-travelled area of study and requires a lot of attention to detail. I have even held forth on it myself:

    Load/Save steps:

    https://forum.unity.com/threads/save-system-questions.930366/#post-6087384

    Don't use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

    https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide
     
    Joe-Censored and none3d like this.
  4. none3d

    none3d

    Joined:
    Mar 4, 2021
    Posts:
    156
    oh bad ! terrain data , navigation data , ... nothing can not save and load again , why !
    How can I record all the trees, grass, and alpha-map textures that the user creates at runtime and re-apply all the changes in the next run before logging in?

    I do not care if the user changes
    Can it be save and load using serialize method?
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Because like I said, those are Editor features. Take a look at your build some time, and try to find the Assets folder. Find your original scene files and individual asset files which you would want saved with changes at runtime. That should give you an idea.
     
    Last edited: Apr 20, 2021
    none3d likes this.
  6. safi95113

    safi95113

    Joined:
    Aug 22, 2022
    Posts:
    1
    @none3d Can you share the script in which you have change terrain texture at specific point