I have searched a lot on how to save a game in Unity 3D. Everyone has advised to use XML serialization or Player Prefs. What i am unable to figure out is what exactly to save. My game is a tower Defence game so when I quit i need to save
Towers (multiple Prefabs , location and each on a particular
upgrade,animation currently playing etc)
Enemies (multiple enemy prefabs on the battle field, their position , animation , enemy path
, health etc)
Enemy Wave
Path Calculations
Difficulty
Level
Score
Lives Left
Total money
what should be my approach trying to save all this information. What is the level of granularity I will have to go to ? . Can I save every gameObject and everything related to that game object will be automatically saved. or do i save every class ? ... or do i need to save every variable used in the game.
It depends on your code design. But avoid saving all data (like serialisation). All that have initial default values or non-important for player (such animation position) should save only changed properties. After game is loaded you should create objects from scratch, init them and set values from saved file.
For simple games can suggest to use Player Prefs to just save such info as current level, score.
For saving thousands of random objects consider saving control points and restore level loading them and regenerate random points around them.
Also good approach is to save data into web cloud.
Related
Lets say, for starters, i have a game. And in that game, I add a few places. If i were to create a datastore in the main GAME, would that transfer to all of the places automatically as well?
Yes, all subsidiary places created under the same game share datastores of the main game. If you want to send specific data to a certain place, use https://developer.roblox.com/en-us/api-reference/function/TeleportService/GetLocalPlayerTeleportData.
Keep in mind that data sent along with teleports is local and can be manipulated by the client.
For example, I would have a main lobby in my Roblox game. Then, a player gets sent into another game and collects coins. When they come back to the lobby after they get a certain amount of coins, I want it to save their all time coins.
I would share code, but I have absolutely no idea how to do this.
Roblox "Games" can hold multiple "Places". Up to 20, I believe, including the "Starting Place". The neat thing about this is that datastores are saved across the entire game. As a result, if you save someone's data in place1, then they move to place2, their data will carry over.
To learn more about Games vs. Places, you can visit the developer API documentation.
EDIT: Alternatively, if you want data to save across multiple games, you would have to look into HTTPService, and off-roblox datastores.
I'm doing my first implementation with Game Center. I'm trying to let players issue GKScore challenges to one another. My game consists of playing a certain number of levels in a random order. (Let's say, a game is 9 levels long, randomly chosen from 30 possible levels.)
When the challenge is issued, I need to be able to include which levels the challenging player played so that the receiving player can play those same levels hopefully in the same order.
I know that I can include a GKScore.context : UInt64 which will get passed back to me, but I'm having trouble figuring out how best to encode my level information to get passed along and was hoping for some pointers toward examples or other solutions/best practices.
I know that I could use bitwise flags to encode which levels should be included in the 9-level-game, but I'm not sure how I could also include the order if I did that.
I know that I could use the GKScore.context to generate a random id number, upload the game info to my server, and then fetch it back down with that same identifier, but I really do NOT want to add a server component to this game which should run entirely on device. I don't want the server load nor the server code maintenance.
What other options have you used for transmitting challenge information with the GKScore.context without relying on a server component?
Generate a random value that will fit in 64-bits. Use that to seed a random number generator and produce whatever level numbers in whatever order you need. Save the seed as the context. For the challenged player, get the seed from the context info and initialize your random number generator with the same seed. You'll get the same sequence of "random" values and hence the same level numbers in the same order. The only network stuff will be through Game Center when it has to deliver the challenge.
I'm having some issues understanding properly how the loading of leaderboard scores actually work.
If I specify a range of the best global scores of 1-25, if the local player is at rank 50, will it still be loaded and be available with leaderboard.localPlayerScore?
Also, are those scores the only scores that are actually loaded onto the device, and the filtering happens on the server, or does the GameKit API actually load everything, and then filters it on the device?
Yes, the localPlayerScore attribute of the GKLeaderboard will be available after loading, regardless of the player's actual rank.
The score filtering happens on server side, as loading every score would be very wasteful. This generally applies to nearly every application that handles network data (unless it relies on offline usage).
I am trying to develop a computer game. I want this game to be multiplayer playable. The game is an arcade space shooter
I plan to run the game at server level and then send updates at the clients. The problem that I am facing is object creation. Let's say if a player shots, the shots themselves are new objects. These will need to be created.
In my game I have a hierarchical structure and the shots themselves will be part of this structure. It will be something like a tree. The problem that I have is identifying objects on the clients and server.
How can I make sure that when the client receives some update then it will update the right objects?
What about new object creation. In my case the scene graph is traversed and each object is updated once it gets updates from the server. But updates which creates new object violates this principle. How should I handle them?
Also, I can't really get updates for the entire scene. I would only need to update specific objects that are visible to the player. What should I do with the rest of the objects that aren't visible? What will happen when they become visible? How can I track when objects become visible to a player?
How can I make sure that when the client receives some update then it
will update the right objects?
You can give an unique id to each object server creates. You might want to create a super Object class containing id and let all other game object classes inherit from it. Or, you can have a map to link between id and object. Or, you can mix them. To get an unique id, server can have a global 'nextID' as int and simply assign to a new object and increase it for next one.
But updates which creates new object violates this principle.
I don't really understand the principle you are talking about but if you are worried about editing your scene graph (or game object list) while traversing it, you can put the newly created objects into another list and just insert the new ones after traversing is done. They will start getting updated from next update. (You should consider how you will remove an object too)
What should I do with the rest of the objects that aren't visible?
What will happen when they become visible?
Well, you are the one who should figure it out because it really depends on your game system. My suggestion is that try to skip their updates and see what problems appear and fix them.
How can I track when objects become visible to a player?
Also, several ways to handle this. Server can detect everything for clients and send only visible object info for each client. Or, each client can detect them and send a request to server for starting to update visible ones. Or, it could be mixed way.
Try server-driven one first and see if server can perform it with maximum number of clients.To use client-driven one, remember each client still needs to update all object location regardless of their visibility but send a request for AI updates for only visible ones.
Again, there are many ways to handle this kind of problems and it really depends on your game system requirements. That's why it's hard to answer your question without knowing your game system well enough. Try to investigate how other similar multiplayer games are designed from some books or google. Good luck!