-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
GDExtension: Use ObjectID
when creating custom callable
#83800
GDExtension: Use ObjectID
when creating custom callable
#83800
Conversation
If overall it takes more work to use an ObjectID I say its fine to let the apis differ from each other. My comment was under the assumption that this was just type semantics. I don't think being 1:1 with the base engine API is worth worse performance. |
Well, it depends on what data you have already, and if it's the common case to have that data or not. For example, if you have an It'd be great to have the perspectives of some other language bindings. |
Atleast for my bindings, I do already have the object pointer its self. under module builds I call |
Maybe to bring another argument to the discussion: So if I have a How does this work in GDScript by the way? Are callables checking their object's validity? |
Made a comment in the other PR, godotengine/godot-cpp#1280 (comment) Basically, I don't have strong feelings either way, but changing may be more in line with the rest of the API and it's general usage (tho even core does weird things here). I think if we go this way it would be best to do this now rather than later. Also, I think there is a typedef for object ids that should be used rather than int. |
0cec4ce
to
b0a33ca
Compare
Thanks for the feedback, Everyone! Personally, I think I'm starting to lean towards the API change in this PR.
Right, and internally Godot is storing an But if the binding is going to have its own object/struct representing a
I agree. This API is new, so if we can sneak a change in now before 4.2, that'd be great. But if we release with the current API, I don't know if it's worth all the backcompat trouble (ie making the duplicate struct and function) to change it in 4.3+.
Ah, good call! I've update this PR to use Anyway, I think I'm going to takes this PR out of draft. But if anyone objects to this change, please let me know! |
Isn't
In the current C# bindings (which don't use the GDExtension APIs) we store a reference to the Object (basically a When the To expand on that. Is it safe for the Object to be null even if the method is not static? If the custom What I'm trying to get to is: if setting the Object is not necessary and this PR is merged, I think in C# we would never set the Object and avoid the extra interop call. But I'm not sure if there are side-effects to doing that. Note that I haven't used the GDExtension APIs much yet. I'm commenting from the perspective of the current C# scripting implementation, and because asking these questions will help me when implementing the C# GDExtension bindings in the future. |
With this function -- it returns null if the ID doesn't point to a valid object. godot/core/extension/gdextension_interface.h Lines 2247 to 2257 in c21c270
No, the object doesn't need to be set for custom callables. If it's set, it will be returned by I implemented custom callables without objects -- sometimes there is not even an object in the Godot sense available (e.g. for closures/lambda expressions). |
Yeah, in an ideal world, the object associated with the In practice, though, there's a number of places in Godot that are checking the object directly to determine if the callable is valid or not. We fixed a whole bunch of them in PR #82695 - we'll probably fix more during the Godot 4.3 development cycle. But for the sake of discussion around this API, I think we should consider the object used for a custom callable to be optional and informational, because that is what we're aiming for it to be. |
ObjectID
when creating custom callable?ObjectID
when creating custom callable
Thanks! |
I have very mixed feelings about this change, but I thought I'd propose it and get some feedback.
As described in this comment, we could make the godot-cpp API mimick the Godot API a little better (without an extra unnecessary hash map lookup) if
GDExtensionCallableCustomInfo
took anObjectID
rather than anObject *
.However, I do think the current API taking an
Object *
makes the most sense when just looking at thegdextension_interface.h
API in isolation. In order to pass in anObjectID
we need to make an extra call into the engine, whereas we're about to call into the engine anyway to pass in theGDExtensionCallableCustomInfo
, so why not let the engine lookup theObjectID
on its side?So, I'm just really not sure. Please let me know what you think!UPDATE: I think I've come around to support the change in this PR. First of all, I think the most common case is just to not have an object on a custom callable. But in the case where there is an object, the GDExtension will probably want to hold on to the
ObjectID
(rather thanObject *
) anyway, in order to check it for validity. So, since it will probably have that data already, it's really not any extra work to provide it when creating the custom callable. Also, it doesn't seem like anyone opposes the change, and in the comments there has been feedback from maintainers of Rust, Lua and Python bindings.