GameObjectExtensions

Extension methods for UnityEngine.GameObject that add parent hierarchy traversal and scene management utilities.

Definition

Namespace: Paragon Assembly: Paragon.dll

public static class GameObjectExtensions

Quick Lookup

Goal
Method

Walk up the parent chain

go.GetParents()

Walk up including self

go.GetParents(includeSelf: true)

Move to a specific scene

go.MoveToScene(scene)

Move to the active scene

go.MoveToActiveScene()

Methods

GetParents

Returns a lazy IEnumerable<GameObject> that yields each parent GameObject by walking up the Transform hierarchy. Optionally includes the source GameObject itself as the first element.

public static IEnumerable<GameObject> GetParents(this GameObject gameObject, bool includeSelf = false)
Parameter
Type
Default
Description

gameObject

GameObject

(required)

The starting GameObject

includeSelf

bool

false

If true, yields gameObject before its parents

Returns: Lazy IEnumerable<GameObject> from immediate parent to root (or self to root if includeSelf is true).

Behavior:

  • Uses yield return — the enumeration is lazy and allocates no intermediate list

  • Yields parents from nearest to furthest (immediate parent first, scene root last)

  • Stops when transform.parent is null (scene root reached)

MoveToScene

Moves the GameObject to the specified scene. Delegates to Paragon.Core.SceneManagement.SceneManager.MoveGameObjectToScene().

Parameter
Type
Description

gameObject

GameObject

The GameObject to move

scene

Scene

Target scene

circle-exclamation

MoveToActiveScene

Moves the GameObject to the currently active scene. Delegates to Paragon.Core.SceneManagement.SceneManager.MoveGameObjectToActiveScene().

Parameter
Type
Description

gameObject

GameObject

The GameObject to move

circle-info

This method is used internally by FactorableBehaviour during OnSpawn() to move pooled objects from the factory's scene to the active scene.

Examples

Walking the Parent Chain

See Also

Last updated