Class PackedDataContainer
- Namespace
- Godot
- Assembly
- GodotSharp.dll
PackedDataContainer can be used to efficiently store data from untyped containers. The data is packed into raw bytes and can be saved to file. Only Array and Dictionary can be stored this way.
You can retrieve the data by iterating on the container, which will work as if iterating on the packed data itself. If the packed container is a Dictionary, the data can be retrieved by key names (string/StringName only).
var data = { "key": "value", "another_key": 123, "lock": Vector2() }
var packed = PackedDataContainer.new()
packed.pack(data)
ResourceSaver.save(packed, "packed_data.res")
var container = load("packed_data.res")
for key in container:
prints(key, container[key])
Prints:
key value
lock (0, 0)
another_key 123
Nested containers will be packed recursively. While iterating, they will be returned as PackedDataContainerRef.
public class PackedDataContainer : Resource, IDisposable
- Inheritance
-
PackedDataContainer
- Implements
- Inherited Members
Constructors
PackedDataContainer()
public PackedDataContainer()
Properties
__Data___
public byte[] __Data___ { get; set; }
Property Value
- byte[]
Methods
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
Pack(Variant)
Packs the given container into a binary representation. The value
must be either Array or Dictionary, any other type will result in invalid data error.
Note: Subsequent calls to this method will overwrite the existing data.
public Error Pack(Variant value)
Parameters
value
Variant
Returns
Size()
Returns the size of the packed container (see Array.size
and Dictionary.size
).
public int Size()