PointerProperty limitations

I made a prop_search which gets the bones of an armature. I wanted to filter these bones so that only bones with a certain value on a custom property would appear in the list.

Come to find out however, bpy.types.Bones (or bpy.types.PoseBones) cannot be used as the type parameter for a PointerProperty, which makes what I wanted to do effectively impossible. (I’d rather just see the whole list of bones than attempt to maintain a manually constructed collection of strings containing bone names to be used as pointers)

As you can imagine, this is mildly frustrating. What I am wondering now is, why is it this way? Ideally, I think most things should be able to be used as the PointerProperty type, given the correct context. But, as of right now, this list is rather thin…I don’t know what it would take to change this, but I really do hope this is worked on.

If anyone has any solutions to recommend which can be implemented using the current Blender API, that would also be welcomed.

Not sure if it’ll help in your case, but you can pass a poll function to the PointerProperty.
When poll returns True for an object, it will be visible in the dropdown list, when poll returns False it’s excluded from the dropdown and can’t be picked.
See for example the “poll_domain” function here: https://github.com/LuxCoreRender/BlendLuxCore/blob/master/nodes/textures/smoke.py

Yes of course, the poll function is the entire purpose of my PointerProperty.

What I just realized though is that I made some incorrect assumptions. I was under the impression that the prop_search I have, when getting bpy.types.Bone from bpy.context armature.bones, would automatically update the reference in the case that the bones name was changed. This turns out to be incorrect…

This now begs the question, how is it done in say, the bones Parent property? Having looked at the script, its prop_search looks almost identical to mine on the surface level, so I guess I’m left to assume it is updated by some lower level function.

I suppose my question now really just boils down to this, how do I update the reference when the referenced bones name is changed?

I think you have to use
layout.prop(self, "your_pointer_prop")
to draw it in the UI, like I do in the code linked above (line 53).

I’m not sure how this is supposed to help since A. as I already explained, the type which I want to point to cannot directly be pointed to, and B. the prop_search whos behavior I wish to replicate does not use a PointerProperty

Sorry, my bad, I overlooked that part in your first post and assumed from the thread title that you were using a PointerProperty.