1
$\begingroup$

(Hi) I was wondering if its possible to create a CollectionProperty (collection_custom_objects) that contains, lets say a class CustomObject(PropertyGroup), and then fill the collection with different objects that inherits that CustomObject(PropertyGroup) class?

For example, if we have:

# Base class
class CustomObject(PropertyGroup):
    ...

# Derived Classes
class ObjectA(CustomObject):
    ...

class ObjectB(CustomObject):
    ...

Is it possible to fill/add to the property with Objects of type ObjectA and/or ObjectB?

As far as I know, if we call collection_custom_objects.add(), we would be adding CustomObject objects.

I tried casting the item that collection_custom_objects.add() returns, like:

item = collection_custom_objects.add() # type(item) = CustomObject class
item = ObjectA(item) # If I print now type(item), I got "ObjectA class"

But when I get manually from the console that element previously added, it says its type is "CustomObject", and it calls the functions from "CustomObject", not from ObjectA.

So, I was wondering if this is something doable and I'm doing something wrong, or if it is not possible and I should give up this approach?

(Thank you so much for reading and for the help)

$\endgroup$
2
  • 2
    $\begingroup$ No is not possible. it only designed for one object type I think $\endgroup$
    – user150719
    Commented Sep 8, 2023 at 15:43
  • 2
    $\begingroup$ nice to know! Thank for the help friend :) $\endgroup$
    – Ommadawn
    Commented Sep 8, 2023 at 15:47

0

You must log in to answer this question.

Browse other questions tagged .