Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created August 18, 2025 23:51
Show Gist options
  • Save kurtdekker/53c1bffe41669fc2defc00a682a54d66 to your computer and use it in GitHub Desktop.
Save kurtdekker/53c1bffe41669fc2defc00a682a54d66 to your computer and use it in GitHub Desktop.
Scene To Text dumper - just for easy note-taking and idea transfer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
// @kurtdekker
//
// A handy way to emit the contents of a scene or prefab as text.
//
// Purpose: documentation and communication in pure text.
//
public static class SceneToText
{
// how many indent characters to insert per depth?
const int indentDepth = 2;
// what to use for the indent? (some contexts will flatten spaces)
const char indentChar = '.';
// everybody has a Transform... do we really need to know about it?
const bool includeTransform = false;
// to understand recursion, you must first understand recursion
static string EmitFullTree(GameObject go, string workString, int indent = 0)
{
string indentString = new string(indentChar, indent * indentDepth);
workString = workString + indentString + go.name + "\n";
Component[] components = go.GetComponents<Component>();
int firstIndex = includeTransform ? 0 : 1;
for (int i = firstIndex; i < components.Length; i++)
{
Component component = components[i];
workString = workString + indentString + ">" + component.GetType() + "\n";
}
if (go.transform.childCount > 0)
{
for (int i = 0; i < go.transform.childCount; i++)
{
Transform child = go.transform.GetChild(i);
workString = EmitFullTree(child.gameObject, workString, indent + 1);
}
}
return workString;
}
[MenuItem("Tools/Emit Scene As Text")]
private static void EmitScene()
{
GameObject[] roots = null;
string output = "Generated from SceneToText.cs:\n\n";
if (Selection.gameObjects.Length > 0)
{
output += "Selection contents:\n\n";
roots = Selection.gameObjects;
}
else
{
output += "Active scene contents:\n\n";
Scene scene = SceneManager.GetActiveScene();
roots = scene.GetRootGameObjects();
}
for (int i = 0; i < roots.Length; i++)
{
GameObject root = roots[i];
output = EmitFullTree(root, output);
}
Debug.Log(output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment