Hide
GetComponentInParent / GetComponentInParents

Automatically assign a component to a field, if the field value is null and the component is already attached to its parent GameObject(s). (First one found will be used)

Note:

  1. Like Unity's GetComponentInParent, this will check the target object itself.
  2. GetComponentInParent will only check the target & its direct parent. GetComponentInParents will search all the way up to the root.

Parameters:

  • (Optional) EXP config: config. See Saints XPath-like Syntax section for more information.

    Note: You can change the default behavior of these attributes using Window/Saints/Create or Edit SaintsField Config

  • (For GetComponentInParents only) bool includeInactive = false

    Should inactive GameObject be included? true to include inactive GameObject.

    Note: only GetComponentInParents has this parameter!

  • Type compType = null

    The component type to sign. If null, it'll use the field type.

  • string groupBy = ""

    For error message grouping.

  • AllowMultiple: No

using SaintsField; [GetComponentInParent] public SpriteRenderer directParent; // equals [GetByXPath("//parent::")] [GetComponentInParent(typeof(SpriteRenderer))] public GameObject directParentDifferentType; // equals [GetByXPath("//parent::/[@GetComponent(SpriteRenderer)]")] [GetComponentInParent] public BoxCollider directNoSuch; [GetComponentInParents] public SpriteRenderer searchParent; // equals [GetByXPath("//ancestor::")] [GetComponentInParents(compType: typeof(SpriteRenderer))] public GameObject searchParentDifferentType; [GetComponentInParents] public BoxCollider searchNoSuch;

get_component_in_parents