Description
The MakeIdGuidsUnique
method is a static utility function provided by the Sandbox.SceneUtility
class. It is designed to ensure that all GUIDs within a JSON object, specifically those labeled as "__guid", are unique. This is particularly useful when duplicating game objects, as it helps maintain unique identifiers and associations across serialized data.
Usage
To use the MakeIdGuidsUnique
method, you need to pass a JsonObject
that contains the serialized data of your game objects. Optionally, you can provide a rootGuid
to specify a starting point for the GUID replacement process. The method will return a dictionary mapping the original GUIDs to their new, unique counterparts.
Example
// Example usage of MakeIdGuidsUnique
using System;
using System.Text.Json.Nodes;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
// Assume jsonObject is a JsonObject containing serialized game objects
JsonObject jsonObject = new JsonObject();
// Optionally, specify a root GUID
Guid? rootGuid = Guid.NewGuid();
// Call the MakeIdGuidsUnique method
Dictionary<Guid, Guid> guidMapping = SceneUtility.MakeIdGuidsUnique(jsonObject, rootGuid);
// Output the mapping of old GUIDs to new GUIDs
foreach (var entry in guidMapping)
{
Console.WriteLine($"Old GUID: {entry.Key}, New GUID: {entry.Value}");
}
}
}