|
I'm making an RPG, and wanted to know how I would be able to retain a GameObject's possibly changed data/variables (such as HP, coordinates, etc.) when switching scenes. I am asking this because when a new scene is loaded all of the previous scene's GameObject's (such as the character object in that scene) data/variables (HP, etc.) will be set to their defaults and all of that mandatory info would be lost. Any help would be appreciated. Thank you!
(comments are locked)
|
|
You could call Object.DontDestroyOnLoad(myGameObject); and then just keep the same gameObject from scene to scene. But this will cause there to be two copies of the items in question when you return to the scene. You'd have the original object in the position you left it, and a carbon copy positioned right where it was in the authoring tool. That's not really helpful.
Mar 29 '11 at 09:35 PM
scriptocalypse
You can create the permanent objects in one scene, set them to not destroy on load, then load the scene you really want to play. Then you never go back to the loading scene, just to the scene you want to play again.
Apr 07 '11 at 05:23 PM
Azound
(comments are locked)
|
|
You could also consider creating a "checkpoint" before level changes where all Data are written e.g. in a Savegame/File/Database and reloaded (respectively only the data needed for the new level) after every level change. Thus you can purge the memory from data unneeded for the scene (e.g in a indoor scene you barely need cooridates of visited places or other data related to outdoor levels) I was sort of thinking of the same idea, but I don't have the slightest clue on how to write data, let alone load it and read it, is there some place you could point me to for help on this?
Jan 31 '10 at 10:54 PM
LHP
I've seen commercial RPGs (e.g. Drakensang) using SQLite files for their savegames. They saved practically everything in there. Depending on your target platform you can use any embedded database, preferable SQlite since there is plenty of documentation and c# wrappers for it.
Feb 01 '10 at 09:11 AM
rawsteel
(comments are locked)
|
|
Another approach (not the best but an easy one) would be making static objects which can store player data. Those objects don't need an instance to be altered, but be careful to reinitialize those objects appropiately. With static objects, you can also avoid passing lots of data from one object to another, or keep looking for objects every scene like in DontDestroyOnLoad() or store data Methods, but player data will be always on memory, and most programmers consider using static objects a bad programming habit.
(comments are locked)
|
