Adding custom properties to collection not working in def draw()

I’m making a script that simplifies exporting multiple mesh object data to fbx.

import bpy


class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Export FBX for UE4//UE5"
    bl_idname = "SCENE_PT_layout_demo"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "context"

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        assets = context.collection.objects
        
        layout.label(text = "Export FBX for UE")
        
        bpy.context.collection["ueExportPath"] = "y:\\temp\\test.fbx"
        print(bpy.context.collection["ueExportPath"])

def register():
    bpy.utils.register_class(LayoutDemoPanel)


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)


if __name__ == "__main__":
    register()

But it does not create custom properties to the active collection with an error:

Python: Traceback (most recent call last):
  File "(...).blend\ueFbxExportv3", line 20, in draw
AttributeError: Writing to ID classes in this context is not allowed: collection_name, Collection datablock, error setting Collection.ueExportPath

Changing string to float does not spew out an error, but doesn’t work anyways.
It works in console and outside class declaration, but does not work inside def draw().
Also it seems like accessing manually created custom properties is impossible as well.

bpy.context.collection["ueExportPath"] = "y:\\temp\\test.fbx"

As I said, just executing this line alone works in console or outside def draw().

That’s not what custom properties are for. Your purpose requires registering a property to an appropriate type and then drawing that property from an instance of the type. Presumably you want a StringProperty with a FILEPATH subtype.

And, as the error informed you, you also shouldn’t be doing anything but drawing in the draw method.