Problem with reparenting objects to joints

I have written a code that makes an actor pick an object by reparenting that object to the actor’s left hand joint. I use exposeJoint to get a reference to a joint nodepath as in the manual and reparent my model to that nodepath. When I call getChildren on the joint nodepath I find my object attached to the hand joint. The problem is that when I call expose joint a second time to get a reference to the same joint node path and then call get children on that joint node, I find that the joint has no children. I can’t understand that behavior.
here is a code snippet for demonstration

    self.c2.model.reparentTo(self.render)

    joints = self.c2.model.getJoints(None,"*LeftHand")
    print(joints)
    print(joints[0].get_name())

    self.joint_left = self.c2.model.exposeJoint(None,'modelRoot',joints[0].get_name())

    self.cup = self.loader.load_model(mp)
    self.cup2 = self.loader.load_model(mp)
    self.cup2.reparentTo(self.joint_left)



    self.cup.reparentTo(self.joint_left)

    self.cup.setEffect(CompassEffect.make(self.render, CompassEffect.PScale))
    self.cup2.setEffect(CompassEffect.make(self.render, CompassEffect.PScale))

    for child in self.joint_left.getChildren():
        print(child)
        if child.getParent()==self.joint_left:
            print("hi")
    self.joint_left = self.c2.model.exposeJoint(None,'modelRoot',joints[0].get_name())
    for child in self.joint_left.getChildren():
        print(child)
        if child.getParent()==self.joint_left:
            print("hi")
1 Like

I suspect that each call to “exposeJoint” returns a new NodePath controlled by the joint, rather than a NodePath directly associated with that joint.

What I imagine that you’re expected to do is to keep a reference to the NodePath returned by your original call to “exposeJoint”, and then continue to use that.

yeah, I suspected that too, but I didn’t think it is logical. I ended up with the solution you proposed. Thank you.