Best way to check is_instance_valid from GDExtension?
Asked Answered
G

3

0

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!

Greave answered 26/8, 2023 at 6:34 Comment(0)
I
1

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

#include <godot_cpp/variant/utility_functions.hpp>
bool valid = UtilityFunctions::is_instance_valid(my_instance);
Illumination answered 17/10, 2023 at 14:29 Comment(0)
G
0

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

Greave answered 27/8, 2023 at 6:13 Comment(0)
P
0

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

Piddle answered 7/10, 2023 at 13:44 Comment(0)
I
1

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

#include <godot_cpp/variant/utility_functions.hpp>
bool valid = UtilityFunctions::is_instance_valid(my_instance);
Illumination answered 17/10, 2023 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.