Skip to content

Instantly share code, notes, and snippets.

@s2kw
Last active May 27, 2026 08:10
Show Gist options
  • Select an option

  • Save s2kw/7d66fb8ad205e586649761a0fb6b7bb8 to your computer and use it in GitHub Desktop.

Select an option

Save s2kw/7d66fb8ad205e586649761a0fb6b7bb8 to your computer and use it in GitHub Desktop.
A text notation for Unity GameObject hierarchies, inspired by the tree command

Prefab Text Notation

A text notation for representing Unity GameObject hierarchies. Based on the output format of the tree command, with additional syntax for components and properties.

Basic Rules

GameObject

Append / to the name.

Player/
├── Model/
└── Weapon/

Component

Prefix with : (no space).

  • Inline form: Components whose properties are all default values can be listed on a single line, comma-separated.
  • Block form: When a component has non-default property values, it is written on its own line with properties as children.
  • Inline and block forms may be mixed under the same GameObject.
Player/
├── :Rigidbody
│   └── mass: 80
├── :CapsuleCollider, MeshRenderer
└── :Animator
    └── controller: @PlayerAC

Property

Written as children of a component, in the form name: value. Default values are omitted.

Namespaces

Use the short name (Image) by default. Qualification is required only when the short name resolves to multiple types.

  • UI.ImageUnityEngine.UI.Image
  • Fully qualified names like UnityEngine.UI.Image are also allowed.

Ambiguous names without qualification are an error.

Value Types

Type Example
int 42
float 1.5
bool true / false
string "hello"
Vector2/3/4 (1, 2) / (1, 2, 3)
Quaternion (0, 0, 0, 1)
Color (1, 0, 0, 1) (RGBA)
enum Continuous (serialized name)
Asset ref @PlayerMat (asset name)
Scene ref $Player/Head (scene path)
null null

Full Example

Player/
├── :Rigidbody
│   └── mass: 80
├── :CapsuleCollider, MeshRenderer
├── :Animator
│   └── controller: @PlayerAC
├── Model/
│   ├── :Transform, SkinnedMeshRenderer
│   └── Hand/
│       └── :Transform
└── UI/
    ├── :Transform, Canvas, CanvasScaler, GraphicRaycaster
    └── HealthBar/
        ├── :Transform, Image
        └── Fill/
            └── :Image
                └── color: (1, 0, 0, 1)

Open Questions

Areas left for future extension:

  • Nested properties: How to represent hierarchical properties like Rigidbody.constraints.freezeRotationX.
  • Arrays and lists: How to represent collection properties like AudioSource.clips (candidate: [0]: @JumpSound).
  • Prefab instances: A way to distinguish GameObjects that are prefab instances.
  • Active state: How to represent active: false.

Prefab Text Notation

UnityのGameObjectヒエラルキーをテキストで表現する記法。tree コマンドの出力形式をベースに、コンポーネントとプロパティの表現を追加したもの。

基本ルール

GameObject

末尾に / をつける。

Player/
├── Model/
└── Weapon/

Component

先頭に : をつける(スペースなし)。

  • インライン形式: すべてのプロパティがデフォルト値のコンポーネントはカンマ区切りで1行に列挙
  • ブロック形式: 非デフォルト値のプロパティがある場合、コンポーネントの子としてプロパティを並べる
  • 同じGameObject配下でインライン行とブロック行は混在してよい
Player/
├── :Rigidbody
│   └── mass: 80
├── :CapsuleCollider, MeshRenderer
└── :Animator
    └── controller: @PlayerAC

プロパティ

コンポーネントの子として 名前: 値 の形で記述。デフォルト値のものは省略する。

名前空間

通常は短縮名(Image)を使用。短縮名が複数の型に該当する場合は修飾が必要。

  • UI.ImageUnityEngine.UI.Image
  • 完全修飾 UnityEngine.UI.Image も使用可

衝突しているのに修飾がない場合はエラー。

値の型

表記例
int 42
float 1.5
bool true / false
string "hello"
Vector2/3/4 (1, 2) / (1, 2, 3)
Quaternion (0, 0, 0, 1)
Color (1, 0, 0, 1) (RGBA)
enum Continuous(シリアル化名)
Asset参照 @PlayerMat(アセット名)
Scene参照 $Player/Head(シーンパス)
null null

完全な例

Player/
├── :Rigidbody
│   └── mass: 80
├── :CapsuleCollider, MeshRenderer
├── :Animator
│   └── controller: @PlayerAC
├── Model/
│   ├── :Transform, SkinnedMeshRenderer
│   └── Hand/
│       └── :Transform
└── UI/
    ├── :Transform, Canvas, CanvasScaler, GraphicRaycaster
    └── HealthBar/
        ├── :Transform, Image
        └── Fill/
            └── :Image
                └── color: (1, 0, 0, 1)

未確定の論点

以下は今後拡張予定の領域。

  • ネストプロパティ: Rigidbody.constraints.freezeRotationX のような階層プロパティの表現
  • 配列・リスト: AudioSource.clips のような配列プロパティの表現(候補: [0]: @JumpSound)
  • プレファブインスタンス: プレファブ参照を持つGameObjectの区別記法
  • アクティブ状態: active: false の表現
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment