Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting from Variant type pulled from metadata is always warned as unsafe despite explicitly checking the type. #95267

Closed
theDoktorJ opened this issue Aug 8, 2024 · 2 comments

Comments

@theDoktorJ
Copy link

theDoktorJ commented Aug 8, 2024

Tested versions

Reproducible in 4.3 RC2, not reproducible in 4.2.1 stable

System information

Godot v4.3.rc2 - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 31.0.15.5244) - AMD Ryzen 7 7800X3D 8-Core Processor (16 Threads)

Issue description

After porting my project from Godot 4.2.1 to 4.3 RC2 I am experiencing a warning that wasn't previously there and should not be:
Casting "Variant" to "WidgetData" is unsafe.
UNSAFE_CAST
widget_panel.gd:12

Steps to reproduce

Enable Unsafe Cast Warning in Project Settings. After attaching metadata of a custom type to an initialized object, pulling the metadata back off the object does not allow for type safety and always throws an error, no matter what is done to confirm the type. The following code, works correctly without the error in 4.2.1 stable. In 4.3 RC2 it throws an Unsafe Cast error.

extends Node2D
var only_once: bool = true

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	set_meta("data", load("res://test_resource.tres"))

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	if (only_once):
		if (has_meta("data")):
			var test: Variant = get_meta("data")
			if (test is TestResource):
				var test_2: TestResource = test as TestResource
				print(test_2.string_name)
		only_once = false

Minimal reproduction project (MRP)

new-game-project.zip

@theDoktorJ
Copy link
Author

Also, I just confirmed that there is no error or warning in 4.2.2 stable with the same project settings.

@dalexeev
Copy link
Member

dalexeev commented Aug 8, 2024

Thanks for the contribution nonetheless!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants