Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Saving my Player's location in the world

Discussion in 'Scripting' started by angelovanosch, Nov 29, 2022.

  1. angelovanosch

    angelovanosch

    Joined:
    Oct 2, 2022
    Posts:
    4
    so I have a mongo db server connected to my game with a username and a password.
    Can anyone tell me how I would save my player location within the game? I have not created my world yet.

    I prefer some kind of Youtube video since I'm a much better visual learner than just reading,

    thank you!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Then you should search Youtube for it! There's only about 18 billion tutorials for loading and saving.

    Persistent game state saving is all EXTREMELY well-traveled ground, even if you've never done it yourself
    .

    Load/Save steps:

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

    An excellent discussion of loading/saving in Unity3D by Xarbrough:

    https://forum.unity.com/threads/save-system.1232301/#post-7872586

    Loading/Saving ScriptableObjects by a proxy identifier such as name:

    https://forum.unity.com/threads/use...lds-in-editor-and-build.1327059/#post-8394573

    When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. The reason is they are hybrid C# and native engine objects, and when the JSON package calls
    new
    to make one, it cannot make the native engine portion of the object.

    Instead you must first create the MonoBehaviour using AddComponent<T>() on a GameObject instance, or use ScriptableObject.CreateInstance<T>() to make your SO, then use the appropriate JSON "populate object" call to fill in its public fields.

    If you want to use PlayerPrefs to save your game, it's always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:

    https://gist.github.com/kurtdekker/7db0500da01c3eb2a7ac8040198ce7f6

    Do not 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
     
  3. angelovanosch

    angelovanosch

    Joined:
    Oct 2, 2022
    Posts:
    4
    But I already did that once I think... But I wonder how does my game now at which location. I am (not saying it level based, because then you could load scene depending on the level the user is at). I'm talking about loading/saving my location like in WoW, Pokemon and Genshin impact.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Really? And yet you wrote this in your first post:

    So now I don't know what to think about your statements above, so I stand by my statements.

    EVERY game uses the same concepts. It's just saving / loading.
     
  5. angelovanosch

    angelovanosch

    Joined:
    Oct 2, 2022
    Posts:
    4
    Do I need to give my world coordinates or what? Like I understand how to update and get thing from my database like score.

    I have made different small games with which I worked with a database.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    You need to save whatever is necessary to restore your player to its original place in the game.

    Let me observe that you are beginning to look like a zero effort poster.

    I say this because 100% of this is painstakingly outlined in the first link I posted above, and now I am pretty sure you never even read it, so this will be my last reply until you prove otherwise.

    The purpose of this forum is to assist people who are ready to learn by doing, and who are unafraid to get their hands dirty learning how to code, particularly in the context of Unity3D.

    This assumes you have at least written and studied some code and have run into some kind of issue.

    If you haven't even started yet, go check out some Youtube videos for whatever game design you have in mind. There are already many examples of the individual parts and concepts involved, as there is nothing truly new under the sun.

    If you just want someone to do it for you, you need go to one of these places:

    https://forum.unity.com/forums/commercial-job-offering.49/

    https://forum.unity.com/forums/non-commercial-collaboration.17/
     
  7. angelovanosch

    angelovanosch

    Joined:
    Oct 2, 2022
    Posts:
    4
    Last time you see me here I guess. Toxic forum.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    If you do come back, please try to look at the available forums. Please post on the 2D forum if you're asking a 2D specific question. For more general scripting questions I would suggest the Scripting forum. I'll move your post there.

    That's kind of an insult to all of those devs that are trying to help other devs here but you're entitled to your opinion.

    I hope you do find what you're looking for.
     
    Kurt-Dekker likes this.