Save SCRIPTABLE OBJECTS - Unity Tutorial

Поділитися
Вставка
  • Опубліковано 5 бер 2021
  • In this video we will learn how to save multiple objects with their position and scripted object references saved. This save system uses Binary and can be used across multiple platforms
    Unity SCRIPTABLE OBJECTS - Tutorial - • Unity SCRIPTABLE OBJEC...

КОМЕНТАРІ • 37

  • @shugabrush3671
    @shugabrush3671 2 роки тому

    Thanks! This was helpful!

  • @BlueHybridGaming
    @BlueHybridGaming Рік тому +2

    that puppy love made this vid even better.

  • @timberdev
    @timberdev 2 роки тому

    Really good and interesting video! I quite enjoy your style of teaching :D

  • @KillerGameDev
    @KillerGameDev 2 роки тому +1

    Ive been doing unity for years... I usually only remove the namespaces when Im done making my scripts and never remove monobehavior because I didnt know when it would mess things up. I really appreciate how you clearly say why you are removing namespaces and monobehavior. Removing as you code is a lot better than optimizing after the fact. =)

    • @kapkoder4009
      @kapkoder4009  2 роки тому +4

      Yup, if we understand why we do even little things, than in the future whenever your working with something that has to do with that one little thing, your knowledge of that one little thing can help you comprehend, work through or even use better methods to run your code
      In fact your ability to code great things has to do with your ability to manipulate your code, and sometimes you just need a bunch of logic lol like wrapping your head around things, I remember coding a waypoint algorithm and I would have to heavily understand every single thing that was happening in my code to figure what was wrong

    • @KillerGameDev
      @KillerGameDev 2 роки тому

      @@kapkoder4009 I like your mindset. Subscribing. =)

  • @xxispade
    @xxispade 3 роки тому

    That was great. I'm hoping to make a metroid style save area.

  • @ghostwarrior8196
    @ghostwarrior8196 3 роки тому +2

    wow there is literally no other video like this

  • @Golden_Hephaestus
    @Golden_Hephaestus Рік тому

    Thank you! However, is there way to load a list of prefabs instead of a single one? Or would I have to copy and past a lot of this for each prefab I want saved? Thank in advance!

  • @WheremyPoptart
    @WheremyPoptart 3 роки тому +3

    The base for this is pretty good but the system currently isn't that great for a large amount of items since each item is being saved in its own file. You can add a list of data to the SaveGameManager and do something like this
    private List fishData = new List();
    private void Save()
    {
    string key = AUDIENCE_KEY + SceneManager.GetActiveScene().buildIndex;
    fishData.Clear(); //Clear the list before saving it or you'll end up duplicating items
    for (int i = 0; i

    • @kapkoder4009
      @kapkoder4009  2 місяці тому

      That’s actually a really good idea. Thank you so much!

  • @WheremyPoptart
    @WheremyPoptart 3 роки тому +1

    public static void Delete(T obj, string key)
    {
    BinaryFormatter formatter = new BinaryFormatter();
    string path = Application.persistentDataPath + SAVES_PATH;
    if(File.Exists(path + key))
    {
    File.Delete(path+key);
    }
    else
    {
    Debug.LogError("Couldn't delete file in " + path + key);
    }
    }
    Use in the SaveSystem script. Can iterate through in the savemanager

  • @facundoflores6084
    @facundoflores6084 2 роки тому +1

    Ok so let me get this. Saves can only stores numbers, strings and bool. So if i want to store an scriptable object I can only store it's name (or id) and Load and Save with that.
    Does that mean that I cannot have 2 scriptable objects with the same name?

    • @kapkoder4009
      @kapkoder4009  2 роки тому

      Why would you use the name to save it?
      In this video we don't save using the fishes in game name, we use its scripted object ASSET NAME, and no asset in unity can share the same name so its perfect for using the asset name as a reference for what type of fish a fish really is, like a minnow or a gold fish?
      They both have the same fish class but only different appearances such as sprite, name and cost and so on so forth
      Hope this clarified things for you :)

  • @Test-qz2ej
    @Test-qz2ej 3 роки тому

    You cool

  • @shinronitgaming486
    @shinronitgaming486 2 роки тому

    Can I have multiple save files using this system? (For the same scene )Because I think you are creting a save file for each fish.

  • @alonsorojas4119
    @alonsorojas4119 2 роки тому

    with this method can i save game objects wih components, for example its box colaider o line render, i wanna save a line render created by two points(this have a child game object) that has been selected for the user, i tried to save this with game objects position, but every line render has the same position.

    • @kapkoder4009
      @kapkoder4009  2 роки тому +1

      Yes you can save that stuff but you can't save components directly
      You can save bools and floats, and say, if has boxcollider than AddComponent() add save the x and y size in float float if needed
      Same thing for the line renderer
      if (hasLineRenderer)
      {
      LineRenderer line = AddComponent();
      float[] positions = new float[2];
      positions.x = savedXValue;
      positions.y = savedYValue;
      line.SetPositions(positions);
      }
      Atleast that's how I remember how to set line points
      Hope this helped

  • @jumpjumpdiegaming
    @jumpjumpdiegaming Рік тому

    Fishes would be the right word :D Because fishes is a word for lots of fish, but lots of different species of fish.

  • @Ziplock9000
    @Ziplock9000 Рік тому

    It's really strange this isn't part of the bulit-in functionality of SO's already as it actually does this in the editor!

  • @Kalahee
    @Kalahee 2 роки тому +2

    TL:DW wersion - Basically, you can't save a scriptable object.
    You'll be pulling its data into a class that can be serialized into a file.

    • @kapkoder4009
      @kapkoder4009  2 роки тому

      Yes sir, but we also go about how to do that, if you already know how to save data then that’s basically what we’re doing

  • @rodrigoprimata6833
    @rodrigoprimata6833 3 роки тому

    loved you and your girl interactions, lol

    • @kapkoder4009
      @kapkoder4009  2 роки тому +2

      I hope you know that the girl at the end was my sister 😅 but the girl I was on call with was my girlfriend
      Don't get it twisted 😤

  • @gooty6185
    @gooty6185 2 роки тому

    Bro can't you save the public variables of a gameobject script when pasting the gameobject

    • @kapkoder4009
      @kapkoder4009  2 роки тому

      What do you mean?

    • @cake8242
      @cake8242 2 роки тому

      @@kapkoder4009 Hello, your video helped me alot. it works fantastic by me. Realy thank you for this! Now i try to save this data to a cloud from google play. do you know what exactly i have to change to save it in a cloud and load it? I use the cloudsavingscript from this video: ua-cam.com/video/kcxmFWKx0T8/v-deo.html
      But I would like to rebuild it so that it fits the storage function as in your video. I think something has to be changed on the path, but I don't know exactly what. could you help me by this pls

  • @neozoid7009
    @neozoid7009 2 роки тому

    How you are using Fish type for instantiation??

    • @kapkoder4009
      @kapkoder4009  2 роки тому +1

      Because Fish is a prefab of a gameObject but I am allowed to say type "Fish" instead of type "GameObject" because the fishPrefab (gameObject) has my Fish.cs script on it
      Therefore, the fishPrefab gameObject classifies as a Fish
      And therefore once more!! I'm a happy coconut 🥥😌😌😌

    • @neozoid7009
      @neozoid7009 2 роки тому

      @@kapkoder4009 what if there is no Fish.cs script attach to it??

    • @kapkoder4009
      @kapkoder4009  2 роки тому

      @@neozoid7009 well you need a script, unless you have a creative way of going around it which there isn't really (to my belief)
      Because if an object has components you need to access (ie. Sprite renderer, collider) than its easier to give that object a script of its own so its own script can have a reference to its components rather than having some other class collect all the components from several objects, doing something with them, and than throwing away the components instead of having them cached
      So make a script for your object
      If your making a penguin, make a Penguin.cs
      If your making a goblin, make a Goblin.cs
      If your making meth, make a Meth.cs
      Hope dis helps

  • @aurealis2041
    @aurealis2041 Рік тому +1

    I see what you did there, trying to trick us that you have a girlfriend. But I won't get tricked, programmers don't talk to women.

  • @random_precision_software
    @random_precision_software 3 роки тому

    Tip!...no one wants to see beds in bedrooms!..there's a reason why you NEVER see anyone else do that!