How to unregister class that is registered in separate source file?

In init.py I am importing several source files (from . import <…>). Each of these source files have their classes registered directly in those source files using bpy.utils.register_class. It doesn’t work to import those files and register them in init.py. When I define a class directly in init.py, it is registered/unregistered in the respective methods. How do I unregister those classes registered in a separate source file?

Hi,

You need to call the unregister from the unregister function of your parent init.py
So the init.py looks like :

from . my_file import my_class_1, my_class_2

my_object_1 = my_class_1()
my_object_2 = my_class_2()

def register():
    my_object_1.register()
    my_object_2.register()

def unregister():
    my_object_1.unregister()
    my_object_2.unregister()

See you :slight_smile: ++
Tricotou

1 Like

What you have is absolutely correct. It can actually be even simpler than that. I just realized I did something really stupid. I was importing the file rather than the class. That’s why I couldn’t register the class in init.py. As soon as I imported the class (and not the file), I can register/unregister it in init.py! Thanks for the help =)