Skip to content

False or misleading var_to_bytes() note about encoding Callable #12077

Description

@MeeM71

Your Godot version:
4.7.stable

Issue description:
The second note says that: "Encoding Callable is not supported and will result in an empty value, regardless of the data." The empty value is technically not empty, because when I've made a simple check in the editor:

func testfunc():
	pass

func _ready():
	var bytes = var_to_bytes(testfunc)
	print(bytes)

It prints [25, 0, 0, 0]. So it's not an empty array, but array with some data. But Callable is not valid after deserialization:

	var restored = bytes_to_var(bytes)
	print("Restored value: ", restored)
	print("Is Callable: ", restored is Callable)
	if restored is Callable:
		print("Is that Callable valid: ", restored.is_valid())

It prints the following:

Restored value: null::null
Is Callable: true
Is that Callable valid: false

I think the documentation would be more accurate if it says that it returns an invalid or empty Callable, rather than suggest that the byte representation is empty.

URL to the documentation page:
https://docs.godotengine.org/en/4.7/classes/class_@globalscope.html#class-globalscope-method-var-to-bytes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:class referenceIssues and PRs about the class reference, which should be addressed on the Godot engine repositoryenhancement

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions