Class that is written to BAM

I created a copy of the Material class under a different name, and it works. However, it stopped being saved in BAM. I get this message.

:util(warning): Objects of type MaterialPBR cannot be read; bam file is invalid.
  static void init_type() {
    register_type(_type_handle, "MaterialPBR",

If this is returned to the old name Material, then the message does not appear. Where else do I need to make edits to make it work?

Make sure that register_with_read_factory is being called at init time. For Material, this is in config_gobj.cxx.

Thanks it works, but it’s not entirely clear why it’s being done outside of the class.

Because it’s not possible to define a function that runs at library load time inside a class.