Changes

Jump to navigation Jump to search
Line 92: Line 92:     
You can also save data to the player's save file, to keep settings per save, by overriding '''ModMeta''''s '''Serialize''' and '''Deserialize''' methods. These use a '''WriteDictionary''', which is just a dictionary of whatever you want, and the game will handle turning it into bits. '''Please note that any custom classes saved using this method ''has'' to have an empty constructor'''. If you want some fields not to be serialized, use the '''[System.NonSerialized]''' attribute. Properties are not serialized, so you need to create backing fields. When you want to save data, create a '''WriteDictionary''' and populate it with values and return it in the '''Serialize''' method, this will then be returned when a save is loaded in the '''Deserialize''' method. There is also a '''LoadMode''' parameter, which tells you whether it was a full save, a build mode save or a company save (Usually used when the player is moving to another map or during multiplayer synchronization), which will allow you to only save data needed for each type. E.g. you probably don't have to save player preferences for a build mode save.
 
You can also save data to the player's save file, to keep settings per save, by overriding '''ModMeta''''s '''Serialize''' and '''Deserialize''' methods. These use a '''WriteDictionary''', which is just a dictionary of whatever you want, and the game will handle turning it into bits. '''Please note that any custom classes saved using this method ''has'' to have an empty constructor'''. If you want some fields not to be serialized, use the '''[System.NonSerialized]''' attribute. Properties are not serialized, so you need to create backing fields. When you want to save data, create a '''WriteDictionary''' and populate it with values and return it in the '''Serialize''' method, this will then be returned when a save is loaded in the '''Deserialize''' method. There is also a '''LoadMode''' parameter, which tells you whether it was a full save, a build mode save or a company save (Usually used when the player is moving to another map or during multiplayer synchronization), which will allow you to only save data needed for each type. E.g. you probably don't have to save player preferences for a build mode save.
 +
 +
Finally, all modbehaviours have access to their '''ParentMod''', this is the class that manages your mod, and through this you can load files using the methods '''LoadTexture''', '''LoadTydFile''', '''LoadAudio''', '''LoadGLTF''' and '''LoadOBJ'''. Note that these methods all use relative paths from where your mod is installed and using ../ won't work.
    
= Events =
 
= Events =

Navigation menu