You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After RC2 in GDExtention properties that are resources (for example, PackedScenes) get reset to <empty> no matter what you do (even if you assign manually from .tscn file)
Steps to reproduce
Have an exposed resource property with GDExtention and try assigning any resource to it.
The Variant containing the PackedScene is being passed from the Godot side to the godot-cpp side
When Ref<T>::Ref(const Variant &p_variant) gets it, it calls Variant::operator Object *() to get the godot::Object (the godot-cpp version of the object - I'll put godot:: in front to try and make that distinction)
Inside Variant::operator Object*() there is this line at the end:
Via a whole bunch of indirection, this leads to a godot::Object being constructed (because the &Object::__binding_callbacks are being passed in), rather than a godot::PackedScene
So, the dynamic_cast<godot::PackedScene>() ultimately fails, because the object isn't a godot::PackedScene (even though the _owner property points to a PackedScene on the Godot side)
Before PR #1037, it was doing a reinterpret_cast<T>() (instead of dynamic_cast<T>()) which would cast the godot::Object to a godot::PackedScene, even though it wasn't actually a godot::PackedScene object. I think this would have made calling any of godot::PackedScene's methods unsafe?
So, I think the solution is figuring out how to have Variant::operator Object*() (on the godot-cpp side - this is getting confusing :-)) actually create a godot::PackedScene rather than a godot::Object? I'm not yet sure how to do that, though.
I'd love some review of my reasoning above from someone who is more familiar with how GDExtension is intended to work. :-)
I think I've got a way to fix this issue but it's kind of involved (requires a change on the Godot engine side, and a new generated file in godot-cpp) and so will probably require a bunch of review and back-and-forth. With the 4.0 stable release coming soon, let's just revert PR #1037 for now, and I can finish a proper fix after 4.0 :-)
Activity
akien-mga commentedon Feb 15, 2023
How are you using GDExtension exactly?
Withaust commentedon Feb 15, 2023
In
.hppfile:In
.cppfile:In RC1 this code worked perfectly fine
akien-mga commentedon Feb 15, 2023
That looks like godot-cpp specifically, not just the lower level GDExtension. I'll move it to the godot-cpp repo.
Withaust commentedon Feb 15, 2023
After manually reverting lines changed by #1037, related to

cast_toeverything started working again[-]Godot RC2 broke GDExtention's resource properties[/-][+]Broken GDExtention's resource properties[/+]dsnopek commentedon Feb 15, 2023
I am able to reproduce this issue! Here's a minimal test project that I created: resource-property-test.zip
I'm still trying to figure out what exactly is happening...
dsnopek commentedon Feb 15, 2023
I'm starting to understand what's going on here:
Variantcontaining thePackedSceneis being passed from the Godot side to the godot-cpp sideRef<T>::Ref(const Variant &p_variant)gets it, it callsVariant::operator Object *()to get thegodot::Object(the godot-cpp version of the object - I'll putgodot::in front to try and make that distinction)Variant::operator Object*()there is this line at the end:godot::Objectbeing constructed (because the&Object::__binding_callbacksare being passed in), rather than agodot::PackedScenedynamic_cast<godot::PackedScene>()ultimately fails, because the object isn't agodot::PackedScene(even though the_ownerproperty points to aPackedSceneon the Godot side)Before PR #1037, it was doing a
reinterpret_cast<T>()(instead ofdynamic_cast<T>()) which would cast thegodot::Objectto agodot::PackedScene, even though it wasn't actually agodot::PackedSceneobject. I think this would have made calling any ofgodot::PackedScene's methods unsafe?So, I think the solution is figuring out how to have
Variant::operator Object*()(on the godot-cpp side - this is getting confusing :-)) actually create agodot::PackedScenerather than agodot::Object? I'm not yet sure how to do that, though.I'd love some review of my reasoning above from someone who is more familiar with how GDExtension is intended to work. :-)
dsnopek commentedon Feb 16, 2023
I think I've got a way to fix this issue but it's kind of involved (requires a change on the Godot engine side, and a new generated file in godot-cpp) and so will probably require a bunch of review and back-and-forth. With the 4.0 stable release coming soon, let's just revert PR #1037 for now, and I can finish a proper fix after 4.0 :-)
Here's a PR #1046 to do the revert