Version: 1.7
LanguageEnglish
  • C#

InstantAssetEditorUtility.WriteInstantAssetTable

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static bool WriteInstantAssetTable(int instanceID, string outputPath);

Parameters

instanceID The instance ID of the Instant Asset table to serialize.
outputPath WriteInstantAssetTable(int instanceID, string outputPath).

Returns

bool True on successful completion, WriteInstantAssetTable(int instanceID, string outputPath).

Description

Writes an Instant Asset table to the specified output path. This method serializes the asset table data associated with the given instance ID.

This method is primarily used to save modified asset tables after operations like merging or subtracting tables. The resulting file can be loaded at runtime by the Instant Asset system.

using UnityEditor;
using UnityEngine;
using System.IO;

public class MergeTablesExample { [MenuItem("InstantAsset/Merge Instant Tables")] static void MergeInstantTables() { // Set the root path for InstantAsset operations InstantAsset.SetInstantAssetRootPath(Application.streamingAssetsPath); // Define table paths string mainTablePath = "Assets/StreamingAssets/assets_prefabs"; string mergeTablePath = "Assets/StreamingAssets/assets_prefabs01"; string resultPath = "Assets/StreamingAssets/merged_table";

// Load the asset tables InstantAssetTable mainTable = InstantAsset.ReadAssetTable(mainTablePath) as InstantAssetTable; InstantAssetTable mergeTable = InstantAsset.ReadAssetTable(mergeTablePath) as InstantAssetTable;

if (mainTable != null && mergeTable != null) { // Perform merge operation mainTable.MergeFrom(mergeTable); // Write the merged result to output file bool success = InstantAssetEditorUtility.WriteInstantAssetTable( mainTable.GetInstanceID(), resultPath);

if (success) { Debug.Log($"Successfully merged and wrote table to: {resultPath}"); } else { Debug.LogError($"Failed to write merged table to: {resultPath}"); }

// Clean up loaded tables InstantAsset.UnloadAssetTable(mainTable); InstantAsset.UnloadAssetTable(mergeTable); } else { Debug.LogError("Failed to load one or both asset tables"); } } }