-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Resources extended from GDExtension classes don't work right in 4.3 #93676
Comments
CC @godotengine/gdextension @godotengine/gdscript |
Thanks! I had some trouble using the MRP locally, so I attempted to reproduce the bug in a new project using godot-cpp, and, unfortunately, I was unable to. I've attached my new project - perhaps, you can help me modify it in order to show the bug? I tried the project in Godot 4.2.2, and the |
Thanks for trying this out! I tested your cpp project and it does seem to be working as intended. Let me take this info back to the GDExt-rust people and see if there's a discrepancy on the rust side making it behave differently than godot-cpp |
@Bromeon Can you check if this is a bug in the Rust bindings or something we broke in Godot 4.3 that affects the Rust bindings? As noted above, so far we haven't been able to reproduce it with godot-cpp. Thanks! |
I downloaded your ZIP file, but couldn't quite follow these instructions. Even with 4.2.2, I get
Are the initial scene files serialized correctly? I would appreciate if you could reduce this example further, so that I can simply start it with:
and it would output "OK" or "FAIL" on the console. Then I wouldn't need to open the editor, save scenes, check diffs etc. Otherwise it's extremely time-consuming to bisect a larger range of versions. Would that be possible? I'll only get around to look into it next week, so take your time. |
With Bromeon's guidance, I changed the dependencies in the
However, when I tried in both Godot v4.2.2 and Godot v4.3-beta2, I was unable to reproduce the issue. Perhaps the build was created on an older commit of the Rust bindings that had a bug? @aekobear Can you try rebuilding the extension with the latest UPDATE: Here is a ZIP with the libextension.so that I built for Linux, in case anyone wants to try dropping that into the MRP. |
So I've been doing some more testing and it's pretty confusing, so the steps to reproduce are important to get right. Initially I tested with @dsnopek's But I suspect the Basically, with the 4.2 lib, you get: [gd_scene load_steps=4 format=3 uid="uid://t1i4yl2r35cw"]
[ext_resource type="Script" path="res://broken/broken.gd" id="1_3406y"]
[ext_resource type="Script" path="res://broken/custom_resource.gd" id="2_jfebs"]
[sub_resource type="MyResource" id="MyResource_6iub0"]
script = ExtResource("2_jfebs")
speed = 2.0
[node name="Node2D" type="Node2D"]
script = ExtResource("1_3406y")
resources = Array[MyResource]([SubResource("MyResource_6iub0")] While with the 4.3 lib, you get: [gd_scene load_steps=3 format=3 uid="uid://t1i4yl2r35cw"]
[ext_resource type="Script" path="res://broken/broken.gd" id="1_3406y"]
[sub_resource type="MyResource" id="MyResource_dp1iy"]
speed = 2.0
[node name="Node2D" type="Node2D"]
script = ExtResource("1_3406y")
resources = Array[MyResource]([SubResource("MyResource_dp1iy")]) which fails, as the subresource is of type Steps to reproduceFor all tests, use a Godot editor build from latest Reproduce with the MRP
Fix the bug with the 4.2 lib
Here's my version of the "fixed" MRP: resource-bug-api-4.2.zip Reintroduce the bug with the 4.3 libFollow the steps precisely here as data gets lost progressively.
I could reproduce this issue with both the original lib in the OP's MRP built against 4.3-beta2, and with my custom build made against latest So that confirms a saving and loading issue with 4.3 for custom resources extending godot-rust GDExtension classes. |
I worked on this issue and compared Rust and C++ GDExtension. I confirm that the Rust version does not work but the C++ version is working fine on master branch. The difference is in the set and get method of the extension. If I think the problem is a side effect from #82554. With the new I made a branch with a little tweak to test the theory and with this modification Rust GDExtension Resource are working fine: master...Hilderin:godot:fix-resources-extended-from-gdextension-classes- I guess the problem could be fixed in Rust side but I think the behavior of These are the MRP projects that I used to test: C++: In both project, open de Broken.tscn To reproduce:
|
Ah, if placeholders are involved, then I guess Rust is making the class as a runtime class? I didn't pick up on that from the source code. Thanks for the further investigation!
The tricky thing is that we don't actually know if a property exists or not. When using runtime classes, the real class is not actually created in the editor, only a placeholder. So, we'll know about "static properties", but the class could use The script API has its own placeholders (via Later I'll try the MRPs and see if I can come up with logic that would work in this case, and with my other tests with runtime classes. |
I just posted PR #94089 which should fix this. In the end, I don't think we actually need to worry about "dynamic properties": since only the placeholder exists in the editor, there wouldn't really be any way to set them anyway. I also noticed a couple other issues/limitations with runtime classes when digging into this that should be addressed by that PR. I tested with my own godot-cpp test project - the most recent C++ MRP from above didn't actually reproduce the problem for me, maybe because it didn't register its custom class as a runtime class? Anyway, it was very easy to reproduce once I knew this was about runtime classes. I've attached my test project. Please let me know if Godot with this PR fixes the issue with Rust in your testing! |
Tested versions
System information
Godot v4.3.beta2 - Fedora Linux 40 (Workstation Edition) - Wayland - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 with Max-Q Design - AMD Ryzen 9 4900HS with Radeon Graphics (16 Threads)
Issue description
I created a GDExtension custom resource called
MyResource
. Then I created a GDScript resource calledCustomResource
which extendsMyResource
and hasclass_name CustomResource
In Godot 4.3 beta 2:
.tscn
file serializes the resource asMyResource
with no reference to theCustomResource
GDScriptIn Godot 4.2 stable:
- when I run my game, CustomResource behaves as expected
- when I save and close Godot, the
.tscn
contains ascript = ExtResource()
pointing the resource to the appropriate GDScriptIf I manually edit the TSCN to include the GDScript reference and then open it in Godot 4.3, everything works correctly until the next time the scene gets saved. So there seems to be some regression in the way resources are created and serialized
Steps to reproduce
I created a custom GDExtension class (in rust) which extends
Resource
. Let's call it MyResourceThen, in GDScript I created a new Resource like this:
Finally, using the editor, I click the button to add a
new CustomResource
to the arrayI am able to set variables on the CustomResource as expected, but when I run the game, it acts as if the resource were a MyResource. And when I close and reboot Godot, the editor now displays it as a
MyResource
instead of aCustomResource
Minimal reproduction project (MRP)
IMPORTANT NOTE 1: deleting the
.godot
folder causes problems with the plugin on the initial load. You will need to reboot godot editor after loading the project for the first time before the plugin will start workingIMPORTANT NOTE 2: part of the bug is that resources aren't being serialized correctly on save, so the scene I upload here will be incorrect. To reproduce, you will need to:
broken.tscn
scene in the editorresources
variable has a single resource calledMyResource
? This is supposed to be aCustomResource
but was serialized incorrectly.MyResource
and insert a newCustomResource
instead`. Hit playprint()
from CustomResource'supdate()
function, you get an error thatupdate()
doesn't exist onMyResource
MyResource
instead ofCustomResource
againThe extension was written in rust using https://github.com/godot-rust/gdext
I included the compiled extension as well as source code for your reference
resource-bug.zip
The text was updated successfully, but these errors were encountered: