How to save custom user preferences for an addon

So I’m trying to get users the ability to set a path, but it gets lost upon a reload.
Am I doing something wrong?
There is no handler for preference change so I assumed blender should somehow save the path, but it doesn’t. I’ve searched a long time and found no demonstration on how to easily save and load prefs

Here you can see what I have (not the whole script, only things related to preferences)

class MyProperties(PropertyGroup):
    pathDir_string: StringProperty(
        name="Path to asset folder",
        description = "Select main asset folder. Will scan subfolders",
        subtype='FILE_PATH',
        )
        
class MSWPropLinker(AddonPreferences):
    bl_idname = __name__
    
    def draw(self, context):
        layout = self.layout
        scene = context.scene
        myProperty = scene.LinkerProperties
        
        row = layout.row()
        row.prop(myProperty, 'pathDir_string', expand=True)



#Register booleans
def register():
    for i in classes:
        register_class(i)
    bpy.types.Scene.LinkerProperties = PointerProperty(type=MyProperties)

    
        
def unregister():
    for i in classes:
        unregister_class(i)
    del bpy.types.Scene.LinkerProperties
1 Like

Ok, I’ve figured it out. The properties that will be saved need to be inside the AddonPreferences class.
Then they will be saved and they can be called with
getInputString = context.preferences.addons[__name__].preferences.pathDir_string