I have an Object and I want to check to ensure it is valid before manipulating it. Now I know the best thing to do in C++ is to properly manage my scope so that there is no possibility for the Object to be invalid, but the extension I am creating (well, porting) is a container and needs to provide that sanity check. Unfortunately, within a GDExtension I have no access to is_instance_valid nor to any suitable method from ObjectDB. Here is what I have currently:

ERR_FAIL_COND_V_MSG(_iter_current == nullptr || _iter_current->get_instance_id() == 0, Variant(),

//etc.

I am not sure if this is sufficient, if it will even work, or if there is a better way. Can anyone help? Thanks!

  • It's available in GDExtension, in the UtilityFunctions class.

    #include <godot_cpp/variant/utility_functions.hpp>
    bool valid = UtilityFunctions::is_instance_valid(my_instance);

What is the etiquette on bumping a post? If I'm breaking it, someone please inform me.

a month later

I'm sorry, but you really need to provide a little more context to understand your issue.

10 days later

It's available in GDExtension, in the UtilityFunctions class.

#include <godot_cpp/variant/utility_functions.hpp>
bool valid = UtilityFunctions::is_instance_valid(my_instance);