Home Website Youtube GitHub

Custom Component Parenting Issue

Has anyone had any issues with a components refusing to parent to components they’ve written themselves?

I’ve got a really simple component Ive put together, the component itself is working as intended and parents into the rig correctly, its just nothing will parent to it, the only way I can get another component to parent to it is if I parent it to the root guide. Components wont parent under the twist_aim or swing_aim guides at all. they just get parented under the rig’s world_ctl

This is the set relations part of the script, its almost identical to another component I have written that works

    def setRelation(self):
    """Set the relation between object from guide to rig"""

    self.relatives["root"] = self.twist_ctl
    self.relatives["twist_aim"] = self.twist_ctl
    self.relatives["swing_aim"] = self.swing_ctl

    self.controlRelatives["root"] = self.twist_ctl
    self.controlRelatives["twist_aim"] = self.twist_ctl
    self.controlRelatives["swing_aim"] = self.swing_ctl

    self.jointRelatives["root"] = 0
    self.jointRelatives["twist_aim"] = 1
    self.jointRelatives["swing_aim"] = 2

I’m totally stumped at this point as to why its not working as expected. Any ideas or insight would be much appreaciated.

Cheers

Rich

I guess what might be helpful to know is, where does the component parenting happen in the mGear rig build and is there a verbose build mode? Maybe theres an error I’m not seeing in the standard output.

Perhaps you can show your code. You’ve shown one isolated section. No saying thats where the trouble is.

As for verbose debugging, have you seen this thread? Not sure if it will help. How to use the stepDict to access ALL the things

"""Component aim hinge module"""

from mgear.shifter import component
from mgear.core import attribute, transform, primitive, applyop
import pymel.core as pm

##########################################################

COMPONENT

##########################################################

class Component(component.Main):
“”“Shifter component Class”""

# =====================================================
# OBJECTS
# =====================================================
def addObjects(self):
    """Add all the objects needed to create the component."""

    self.root_pos = self.guide.tra["root"],
    self.twist_aim_pos = self.guide.tra["twist_aim"],
    self.swing_aim_pos = self.guide.tra["swing_aim"]

    # Create joint driver groups and aim targets
    self.twist_jnt_drv = primitive.addTransform(
        self.root,
        self.getName("twist_jnt_drv"),
        self.root_pos
    )

    self.swing_jnt_drv = primitive.addTransform(
        self.root,
        self.getName("swing_jnt_drv"),
        self.root_pos
    )

    self.twist_aim = primitive.addTransform(
        self.root,
        self.getName("twist_aim_grp"),
        self.twist_aim_pos
    )
    self.swing_aim = primitive.addTransform(
        self.root,
        self.getName("swing_aim_grp"),
        self.swing_aim_pos
    )

    self.jnt_pos.append([self.twist_jnt_drv, "twist", "parent_relative_jnt", False])
    self.jnt_pos.append([self.swing_jnt_drv, "swing", None, False])

# =====================================================
# ATTRIBUTES
# =====================================================
def addAttributes(self):
    """Create the anim and setup rig attributes for the component"""
    pass

# =====================================================
# OPERATORS
# =====================================================
def addOperators(self):
    """Create operators and set the relations for the component rig

    Apply operators, constraints, expressions to the hierarchy.
    In order to keep the code clean and easier to debug,
    we shouldn't create any new object in this method.

    """
    # aim gun ctl at gun target ctl
    applyop.aimCns(
        self.twist_jnt_drv,
        self.twist_aim,
        axis="zy",
        wupType="object",
        wupVector=[0, 1, 0],
        wupObject=self.swing_aim,
        maintainOffset=False
    )
    # aim gun joint group at gun control target group
    applyop.aimCns(
        self.swing_jnt_drv,
        self.swing_aim,
        axis="xy",
        wupType="object",
        wupVector=[0, 1, 0],
        wupObject=self.twist_aim,
        maintainOffset=False
    )


# =====================================================
# CONNECTOR
# =====================================================
def setRelation(self):
    """Set the relation between object from guide to rig"""

    self.relatives["root"] = self.twist_jnt_drv
    self.relatives["twist_aim"] = self.twist_jnt_drv
    self.relatives["swing_aim"] = self.swing_jnt_drv

    self.controlRelatives = None

    self.jointRelatives["root"] = 0
    self.jointRelatives["swing_aim"] = 1

def addConnection(self):
    """Add more connection definition to the set"""
    self.connections["standard"] = self.connect_standard

def connect_standard(self):
    """standard connection definition for the component"""
    self.parent.addChild(self.root)

    twist_aim_target = self.rig.findRelative(self.settings["twistAimTarget"])
    swing_aim_target = self.rig.findRelative(self.settings["swingAimTarget"])
    if pm.objExists(twist_aim_target):
        pm.parentConstraint(twist_aim_target, self.twist_aim, mo=True)
    if pm.objExists(swing_aim_target):
        pm.parentConstraint(swing_aim_target, self.swing_aim, mo=True)

Thats the componant _ _ init _ _.py as you can see its not that complicated which is why I’m so flummoxed that other componants refuse to parent to it

And here is the guide

class Guide(guide.ComponentGuide):
"""Component Guide Class"""

compType = TYPE
compName = NAME
description = DESCRIPTION

author = AUTHOR
url = URL
email = EMAIL
version = VERSION

def postInit(self):
    """Initialize the position for the guide"""
    self.save_transform = ["root", "twist_aim", "swing_aim"]

def addObjects(self):
    """Add the Guide Root, and locators"""

    self.root = self.addRoot()
    vTemp = transform.getOffsetPosition(self.root, [-20, 0, 0])
    self.twist_aim = self.addLoc("twist_aim", self.root, vTemp)
    vTemp = transform.getOffsetPosition(self.root, [0, -20, 0])
    self.swing_aim = self.addLoc("swing_aim", self.root, vTemp)

    centers = [self.twist_aim, self.root, self.swing_aim]
    self.dispcrv = self.addDispCurve("crv", centers)

def addParameters(self):
    """Add the configurations settings"""

    self.p_twist_aim_target = self.addParam("twistAimTarget", "string", "")
    self.p_swing_aim_target = self.addParam("swingAimTarget", "string", "")
    self.pUseIndex = self.addParam("useIndex", "bool", False)
    self.pParentJointIndex = self.addParam(
        "parentJointIndex", "long", -1, None, None)

So I’ve finally found the issue. I dont know if this is a bug or on purpose as I’ve not seen it mentioned anywhere but if you have an underscore in the guide transform name then you wont be able to parent other componants to it.

this will work: self.save_transform = [“root”, “twistAim”, “swingAim”]

this won’t: self.save_transform = [“root”, “twist_aim”, “swing_aim”]

6 Likes

Doh, Yes

Thanks for this. It’s fixed my issue with my custom face rig.

1 Like

No worries. Glad it helped :smiley:

1 Like