Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Documentation/command-dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ UnityDataTool dump <path> [options]
| `-o, --output-path <path>` | Output folder | Current folder |
| `--stdout` | Write the dump to stdout (status and errors go to stderr). Mutually exclusive with `-o`. | `false` |
| `-f, --output-format <format>` | Output format | `text` |
| `-s, --skip-large-arrays` | Skip dumping large arrays | `false` |
| `-a, --show-large-arrays` | Dump the full content of large arrays of basic data types, instead of summarizing them with a hash | `false` |
| `-i, --objectid <id>` | Only dump object with this ID | All objects |
| `-t, --type <type>` | Filter by object type (ClassID number or type name) | All objects |
| `-d, --typetree-data <file>` | Load an external TypeTree data file before processing (Unity 6.5+) | — |
Expand All @@ -36,9 +36,9 @@ Dump a single object by ID:
UnityDataTool dump /path/to/file -i 1234567890
```

Skip large arrays for cleaner output:
Dump the full content of large arrays (e.g. mesh or texture data):
```bash
UnityDataTool dump /path/to/file -s
UnityDataTool dump /path/to/file -a
```

Dump only MonoBehaviour objects by type name:
Expand Down Expand Up @@ -177,6 +177,22 @@ ID: -8138362113332287275 (ClassID: 135) SphereCollider

---

## Large Arrays

Arrays of basic data types with more than 256 elements (e.g. mesh vertex data, texture bytes) are not printed element by element. Instead the content is summarized with a hash (a CRC32 of the raw bytes), similar to the `-largebinaryhashonly` option of Unity's `binary2text` tool:

```
m_IndexBuffer (vector)
Array<UInt8>[2232]
ArrayDataHash 3be77a33
```

This keeps the output readable while still allowing a diff of two dumps to detect content changes. Pass `-a` / `--show-large-arrays` to print every element instead.

(The former `--skip-large-arrays` option is deprecated: it is accepted but ignored, since large arrays are now summarized by default.)

---

## Understanding PPtrs

PPtrs (Property Pointers) are Unity's mechanism for referencing objects:
Expand Down
13 changes: 10 additions & 3 deletions TextDumper/TextDumperTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace UnityDataTools.TextDumper;

public class TextDumperTool
{
// Arrays of basic types with more elements than this are summarized with a hash
// unless --show-large-arrays is passed.
const int MaxInlineArraySize = 256;

StringBuilder m_StringBuilder = new StringBuilder(1024);
DumpOptions m_Options;
string m_TypeFilter; // m_Options.TypeFilter normalized: null when blank/unset, otherwise the user-provided string
Expand All @@ -29,7 +33,7 @@ public class DumpOptions
public DumpFormat Format { get; init; } = DumpFormat.Text;
public string Path { get; init; }
public string OutputPath { get; init; }
public bool SkipLargeArrays { get; init; }
public bool ShowLargeArrays { get; init; }
public long ObjectId { get; init; }
public string TypeFilter { get; init; }
public bool ToStdout { get; init; }
Expand Down Expand Up @@ -365,9 +369,12 @@ void DumpArray(TypeTreeNode node, ref long offset, int level)
{
AppendIndent(level + 1);

if (arraySize > 256 && m_Options.SkipLargeArrays)
if (arraySize > MaxInlineArraySize && !m_Options.ShowLargeArrays)
{
m_StringBuilder.Append("<Skipped>");
// Summarizing with a hash keeps the output readable while a diff of two dumps
// still detects content changes (same idea as binary2text -largebinaryhashonly).
m_StringBuilder.Append("ArrayDataHash ");
m_StringBuilder.Append(m_Reader.ComputeCRC(offset, dataNode.Size * arraySize).ToString("x8"));
offset += dataNode.Size * arraySize;
}
Comment thread
SkowronskiAndrew marked this conversation as resolved.
else
Expand Down
27 changes: 26 additions & 1 deletion UnityDataTool.Tests/DumpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,34 @@ public async Task Dump_Stdout_AssetBundle_SerializationDemo_ContainsExpectedFiel
Assert.That(output, Does.Contain("charValue (UInt16) 90"));
Assert.That(output, Does.Contain("stringValue (string) SerializationDemo string value"));

// Int array of 512 values (0..511). Check the header and a slice of the sequence.
// Int array of 512 values (0..511), above the large-array threshold so it is
// summarized with a hash by default (CRC32 of the 2048 little-endian bytes).
Assert.That(output, Does.Contain("Array<int>[512]"));
Assert.That(output, Does.Contain("ArrayDataHash 6feca6e2"));
Assert.That(output, Does.Not.Contain("293, 294, 295, 296,"));
}

[Test]
public async Task Dump_Stdout_ShowLargeArrays_PrintsFullArrayContent()
{
using var sw = new StringWriter();
var currentOut = Console.Out;
try
{
Console.SetOut(sw);
Assert.AreEqual(0, await Program.Main(new string[] { "dump", m_SerializationDemoBundlePath, "--stdout", "--type", "MonoBehaviour", "--show-large-arrays" }));
}
finally
{
Console.SetOut(currentOut);
}

var output = sw.ToString();

// The 512-element int array (0..511) is fully dumped. Check the header and a slice of the sequence.
Assert.That(output, Does.Contain("Array<int>[512]"));
Assert.That(output, Does.Contain("293, 294, 295, 296,"));
Assert.That(output, Does.Not.Contain("ArrayDataHash"));
}

// GUID and Hash128 fields are printed as a single hex string instead of their serialized fields.
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading