godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.74k stars 575 forks source link

Directly get object instance ID from `Variant` and implement `Variant::get_validated_object()` #1591

Closed dsnopek closed 2 weeks ago

dsnopek commented 2 months ago

This will fix issue https://github.com/godotengine/godot-cpp/issues/1587 after Godot PR https://github.com/godotengine/godot/pull/97119 is merged (which probably means Godot 4.4+)

It allows us to safely call Variant::operator ObjectID() even on objects that have been freed, and implements Variant::get_validated_object() which exists in Godot itself, and is a very convenient way to check if an object is valid.

Marking as a draft until PR https://github.com/godotengine/godot/pull/97119 is merged