1
$\begingroup$

Im making an "Element class". Every element can be parented to another element. So, I would like to have a parent property like:

class Element(PropertyGroup):
    parent : PointerProperty(type=Element)

Where "parent" points to another Element. However, I get an error.

I wanted to know if it was possible to avoid it or anything (I thought about parent:PointerProperty(type=PropertyGroup), but I guess it wont work), since not having that refference will make my code more complicated.

Thank you so much.

$\endgroup$
5
  • 1
    $\begingroup$ provide the complete code that we can run. $\endgroup$
    – Karan
    Jul 9, 2023 at 19:17
  • 1
    $\begingroup$ What are you trying to do? Explain properly in your question. $\endgroup$
    – Karan
    Jul 9, 2023 at 19:26
  • $\begingroup$ @Karan I'm trying to make some kind of Tree view for some objects, so each element can have child's and parents. That piece (causing the problem) is the basic part to reproduce the problem/point of my question. (Also, is not that I have the UI made yet or anything. I'm making base classes first) $\endgroup$
    – Ommadawn
    Jul 9, 2023 at 20:56
  • 1
    $\begingroup$ It is not possible but you can use an alternative solution. You can add an id property to your property group and use that to store a eference between your property group instances. Add a place where you store all your instances, and then you can search for the right one at runtime. A bit more work, but it works. $\endgroup$
    – Gorgious
    Jul 10, 2023 at 5:35
  • $\begingroup$ Yes, very good idea @Gorgious. Thank you :) $\endgroup$
    – Ommadawn
    Jul 10, 2023 at 9:17

1 Answer 1

2
$\begingroup$

It's not possible to have a PointerProperty with the same type as the current class because a subclass of bpy.types.PropertyGroup or bpy.types.ID has to be registered before using it as a PointerProperty type.

$\endgroup$
1
  • $\begingroup$ Thank you so much for the help @Karan. Indeed, now you said it totally makes sense not being able to use it before registering. $\endgroup$
    – Ommadawn
    Jul 10, 2023 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .