Is it possible to store different types (with a shared base class) in a CollectionProperty?
I want each object to have a set of "Components". Each of these components will have its own PropertyGroup that contains various different settings.
e.g. something like the following:
class Property_Component(bpy.types.PropertyGroup):
type = bpy.props.EnumProperty(items=component_types_array)
class Property_ComponentList(bpy.types.PropertyGroup):
components = bpy.props.CollectionProperty(type=Property_Component)
class Property_Component_Water(Property_Component):
wave_height = bpy.props.StringProperty(...)
color = bpy.props.FloatProperty(...)
class Property_Component_Terrain(Property_Component):
max_height = bpy.props.FloatProperty(...)
# other component types...
However, I'm having trouble actually creating the different types. I know what type to add to the collection, but calling component_list.components.add()
just creates an object of type Property_Component, instead of the derived type, and I don't seem to be able to assign an object of the correct type afterwards.
Is there a way to do this? or some way to work around this?
Something magical with PointerProperty's? Or maybe just give each object an instance of every component (ick), with a boolean to show if it's actually used or not?